This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes RMI and Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI and Synchronization" Watch "RMI and Synchronization" New topic
Author

RMI and Synchronization

mayuresh chaubal
Greenhorn

Joined: Dec 15, 2005
Posts: 12
Scene 1 :
In STUB, I have a synchronized method.
When multiple clients download the stub and call the method, I can see the calls are synchronized, (ie no 2 thread are accessing internal method code at same time).
Scene 2 :
Stub method is not synchronized.
But, it calls methodA() of singleton object, and methodA() is synchronized.
Internally methodA() a does some time consuming work.
Again, when multiple clients call the stub method (which internally calls methodA()), i see that code inside methodA() is thread safe.
Above thing worked on both windows and linux.

Question:
1. In scene 1, is the implementaion specific to vm version,flavour,os ??
can someone lead me to specific documentation which describes internal behavior ?
2. In scene 2, isn't the singleton object serialized and copied down to client vms ??

If not can someone point to sun documents describing the behaviour ??

Thanks in advance ..
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

mayuresh:
In STUB, I have a synchronized method.


I am not sure what are you referring to as STUB?
RMI generates stubs from remote interfaces (if you are on jdk 5 or above, you do not even need stubs, RMI uses dynamic proxies).
So, how can you add a synchronized method in stubs?

If you are referring to the server class implementing the remote interface as STUB, then that class never gets serialized and sent to any VM, unless ofcourse you pass the same class as an argument/return value to/from a remote method.

Unless you are on a fairly old jdk version(I am not sure but some people say there was some problem with the Java memory model in old jdk versions like 1.1 or something) you really do not have to bother about the synchronization guarantees.


apigee, a better way to API!
mayuresh chaubal
Greenhorn

Joined: Dec 15, 2005
Posts: 12
hi nitesh,
i am refering to implemented class as stub.
thanks for the answer
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by mayuresh chaubal:
hi nitesh,
i am refering to implemented class as stub.
thanks for the answer


Then thats a wrong terminology. This is a wiki entry defining stubs.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RMI and Synchronization
 
Similar Threads
NX: cacheless design to keep things simple?
Diff between the given four Synchronized blocks
Doubt in Threads
Reflections on singleton and synchronized methods
RMI and Synchronization