• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking not working properly in seperate VMs

 
Charu Krishnan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic