wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Is it possible to synchronize on/lock an object obtained from JNDI 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 » EJB and other Java EE Technologies
Bookmark "Is it possible to synchronize on/lock an object obtained from JNDI" Watch "Is it possible to synchronize on/lock an object obtained from JNDI" New topic
Author

Is it possible to synchronize on/lock an object obtained from JNDI

Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
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?

Thanks!
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Dan,

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
Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
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?
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi,

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to synchronize on/lock an object obtained from JNDI
 
Similar Threads
Thread Synchronization query
Can two threads call two different synchronized instance methods of an Object?
Code example to help understand Thread question
regaring threads
regaring threads