RMI and synchronization
843793Jun 21 2002 — edited Jun 24 2002There doesn't appear to be much material available on synchronization or mutual exclusion with regards to RMI, so I just want to ensure that I understand the way in which it all works. If anybody can also provide some good articles or book references on this subject, that'd be great too.
As I understand it, whenever a client obtains a stub reference by using JNDI and subsequently executes a remote invocation, the RMI server will respond by creating a (or presumably reusing an existing) Thread that is guaranteed to be used by only one client request at a time. This Thread then simply forwards the request on to the bound remote object. If the invocation's target method is a synchronized method, the Thread that this incoming request is assigned to owns the object monitor for this remote object for the duration of this invocation. From here on in, everything works exactly as local synchronization does.
Synchronized access to a stub is only required is in situations in which you would normally synchronize access to a local object; specifically, whenever there is a chance that more than one Thread in your application may attempt to access the stub at the same time. Obviously, synchronizing on a stub has absolutely no effect on the object on the server to which the stub points, so it is therefore impossible to synchronize access to a remote object for longer than a single method invocation (unless the remote method in turn encapsulates several other operations).
Am I on target?