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 ??
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.