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 Locking not working properly in seperate VMs 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 "Locking not working properly in seperate VMs" Watch "Locking not working properly in seperate VMs" New topic
Author

Locking not working properly in seperate VMs

Charu Krishnan
Greenhorn

Joined: Oct 24, 2000
Posts: 19
Hi,
My lock function does not seem to work as intended in seperate VMs. I am testing it by creating a lock and unlock button in my GUI that just has the lock /unlock code. I start the server and registry and that works ok. Then start one client in local mode on my machine and lock a recoed (say 12). Then open another DOS window and try to lock the same record. But it allows me to lock the same record.(It does not go into the wait code as I expected). As I understand RMI implements multithreading so I have not anywhere in my code implicitly started a new thread. Is that Ok?.
Here is my code for the lock and unlock. Your comments would be much appreciated. How to mak ethis work properly on a separate VM

Regards
Charu
[ Please use CODE tags around code -- PdH ]
[This message has been edited by Peter den Haan (edited September 26, 2001).]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Your logic looks right to me - verify that the problem isn't elsewhere: is the record really locked, isn't it unlocked, are you looking at the same r_lock object, &c?
Validation in lock() is a bit overenthusiastic - an IOException is thrown if record is -1 (database lock). Also, a synchronized Map is used for r_lock. You don't need a synchronized data structure however because you already have to explicitly synchronize access. And, as the code currently is, it really wants to be a Set.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Locking not working properly in seperate VMs