简体   繁体   English

远程调用java方法-如何访问局部变量

[英]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. 我想创建一个也可以充当客户端的rmi服务器,尽管这个方面工作得很好-我遇到的一个问题是,对于任何特定的服务器/客户端关系,更改实例上的本地变量(暂时)为服务器(以及因此远程触发的方法)不会持续存在。

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? 在C ++中(如果您有rmi :)我可以传递一个指针-但是如何强制Java更改基础值?

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. 在这种情况下,仅在客户端上创建一个存根,并且所有方法调用都转到服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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