File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI & record locking.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI & record locking.." Watch "RMI & record locking.." New topic
Author

RMI & record locking..

Jacob George
Ranch Hand

Joined: Jun 26, 2001
Posts: 46
Hi,
I have noticed that many of my friends in this group are changing the signature of lock(int) to lock(clientID,int), where clientID is the unique ID assigned to the remote client using a factory (probably). Will it be correct if I enter the locking information into a HashMap with the Thread.currentThread() as the key and record value as the value. If I adopt this way, I could manage to implement lock() and unlock() without changing the method signature.But, in this case, I am assuming that there will be a unique Thread for servicing each client. Is this assumption correct? Please let me know about it.. Thanking You..
best regards,
Jacob George
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
RMI does not guarentee that you will get the same thread for consectutive remote calls... so you can not use that as your id.
What most people do is use a connection factory that returns new remote objects to the clients. Then the remote object (this) can be used as the id.


scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Jacob,

Will it be correct if I enter the locking information into a HashMap with the Thread.currentThread() as the key and record value as the value. If I adopt this way, I could manage to implement lock() and unlock() without changing the method signature.

Nate's right, can't trust the thread for id in RMI. Also you don't have to change the lock and unlock signatures in you public Data interface. You still call lock(record) and unlock(record) from the client, then the remote implementation object passes that call on to lockManager.lock(record, this) and lockManager.unlock(record, this).
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Jacob George
Ranch Hand

Joined: Jun 26, 2001
Posts: 46
Hi,
ThankYou very much for u'r help. I will have the locking information with 'this' as the key and in that case I wont have to change my method signature. Once more thanks for the tip.
regards Jacob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI & record locking..
 
Similar Threads
Locking with a cookie
client id generation.
URLyBird question
Peter, please review LockManager
lock/unlock