Do I use the same instance of remote object?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jim_geng
Posted On:   Wednesday, June 13, 2001 08:06 AM

In my server program, I do things like:
Engine engine=new ComputorEngine();
Naming.bind("MyObject",engine);
.....

Then in my client program, I do things like:
Engine e=Naming.lookup("MyObject");
e.methed();
......

My question is: is e in client the same object of engine in server? that is if two clients in different JVM call Naming.lookup("MyObject") at the same time, do they get the same instance of Engine so the methods in Engine have to be synchronized?

jim

Re: Do I use the same instance of remote object?

Posted By:   Edward_Harned  
Posted On:   Friday, June 15, 2001 07:29 AM

First -- you do not get an instance of the remote object but rather a reference to the instance of the remote object. Think of the String Object within a JVM:




String a = new String("AAAA");

String b = a;



Both a and b are references to the same object "AAAA".




The RMI Registry contains a reference to the remote object, 'Engine'. Any client may
contact the Registry and request a reference to 'Engine'. Any client may invoke methods in 'Engine' in any order, so the work the methods do must be thread safe.



The RMI Runtime [usually] creates a new RMI-Connection thread for each request, (method invocation from a client). While the methods themselves are not synchronized, if you
manipulate any data that are shared between threads, then you must do that which is necessary to assure integrity, (this usually means to use the synchronized statement.)

About | Sitemap | Contact