Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI and Synchronization

 
mayuresh chaubal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mayuresh chaubal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi nitesh,
i am refering to implemented class as stub.
thanks for the answer
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic