开发者

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 in开发者_开发百科to 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜