• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock Manager problem

 
CyJenny Wong
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have simulate one case with 3 clients connect to the database at server side thru remote connection.
The scenario is as follows:
  • 1st client lock record 1 for booking the flight
  • 2nd client login and try to book the same flight as 1st client, however it is in waiting stage
  • 3rd client book same flight again, also put in waiting stage
  • now when 1st client finish the booking and unlock the record, both 2nd & 3rd client got notified and they can successfully locked the same record simultaneously.


  • Is there any wrong with my lock mechanism, as I supposed while 1st client unlock, either 2nd or 3rd client will get the lock where one of them will still put in waiting stage. Any idea??
     
    Michael Morris
    Ranch Hand
    Posts: 3451
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi CyJenny,
    If two clients can at any time lock the same record simultaneously then you definitely have a problem. What should happen is Client 1 locks the record, Clients 2 and 3 attempt to lock but since Client 1 has the lock, they both go into the objects wait pool. Client 1 unlocks, then when notifyAll() is called, either Client 2 or Client 3 comes out of waiting (no way to determine which). The lucky client now acquires the lock. When that client releases the lock and notifyAll() is once again called, the last client gets the ball and locks the record.
    To accomplish this, you need to make sure that if a particular record is already locked, you should call wait() in your lock method. Every time unlock is called you should call notifyAll(). Make sure that your notifyAll() isn't embedded in a block that might not be called.
    Hope this helps,
    Michael Morris
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic