简体   繁体   中英

remotely called java method - how to access a local variable

i want to create an rmi server that can also act as a client, although this aspect works fine - a problem ive run into is that for any particular server/client relationship, changing a local variable on the instance acting (for the moment) as the server (and thus the method being triggered remotely) does not persist.

So next time i try to access this variable or return it, the original, unchanged variable comes through.

In C++ (if you had rmi :) i could have passed a pointer - but how can i force java to change the underlying value?

How are you transmitting the remote object? There are two mechanisms, remote stubs and serialization. Since you are talking about accessing fields, I assume you use serialization (remote stubs are just interfaces, only methods, no fields).

Objects that are serialized are transferred as a copy. They are just value objects that will not be impacted by whatever happens to "their" version on the server later on. If you need an object that continues to "live" on the server, you have to use a Remote object. In this case, only a stub is created on the client, and all method calls go to the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM