且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java RMI:更新服务器中的客户端对象

更新时间:2023-10-17 20:02:28

当你使用RMI时,你有2个(或者更多)在给定计算中涉及的java虚拟机,因此当您在客户端创建对象并在服务器上调用传递此对象作为参数的方法时,对象的状态将被序列化并通过网络发送。在服务器端,创建同一类的新对象并在其上设置状态,但它是一个具有相同值的不同对象。在此克隆上运行不会反映仍然驻留在源虚拟机上的原始对象。

When you use RMI you are having 2 (or more) java virtual machines involved in a given computation, so when you create an object at the client side and call a method on the server passing this object as an argument the state of the objectis serialized and sent through the network. On the server side a new object of the same class is created and the state is set on it, but it is a different object with the same values in it. Operating on this clone won't reflect on the original object that is still residing on the source virtual machine.

您必须在运行a的每台计算机上使用rmiregistry虚拟机并注册每个对象以显示它(这是一个分布式解决方案),或者您可以将所有数据对象集中在具有rmiregistry的计算机上(这是一个集中式解决方案,因为所有对象都在同一台机器上)。

You would have to use a rmiregistry on each machine that runs a virtual machine and registering each object to expose it (this is a distributed solution) or you could concentrate all the data objects on the machine that has the rmiregistry (this is a centralized solution, since all objects are on the same machine).

干杯