If I store an object (say a List object) in JNDI, and then two different users on two different computers each pull out that object at the same time, is there a way to synchronize/lock the object and changes to it?
Is there a type of object that can be stored in JNDI to do this? Does JNDI have methods to do it?
There are at least two types of objects that an application can bound into the jndi tree: ordinary java objects and rmi objects. For the formal there isn�t much to synchronize if the clients are remote, because they will always get a serialized copy of the object. For the latest the story is quite different, because the clients will get a stub and they will both access remotely the same rmi object. In your case if an application will bind the list into the jndi tree, then clients will have no way to synchronize the access to that list. On the other hand if you wrap the list within an rmi object that provides synchronized access to the list and bind the rmi object to jndi, then the list will be synchronized. However the choice you should remember that the problem could get easily very complex, if you need the list to be available within a cluster. Most app servers provides a cluster-aware jndi that replicates automatically (via ip-multicast) rmi objects. It is also important to know that the object will probably be removed from jndi if the application that bounds it will shutdown. Regards.
I think, therefore I exist -- Rene Descartes
Joined: Feb 25, 2003
Thanks for the reply.
Can any JNDI-compliant server hold an RMI object? I'm assuming the object placed into JNDI is a stub, correct? And the RMI server is separate from the JNDI server?
Joined: Feb 17, 2005
In theory rmi is just a simple and direct model for distributed computing using Java. It doesn�t require any special container or application server and is completely independent from jndi; rmi has its own registries for that. On the other hand if you�d like to use rmi with some jndi implementation (let�s say replacing rmi registers with jndi), the problem won�t be trivial unless you use a middleware capable to provides such services. An example could be the weblogic server or other ejb containers. Jus to satisfy my curiosity: what is actually that you�re trying to achieve? Regards.