Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock question

 
jefferson p
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm using the following snippet for locking:

and the opposite for unlocking:

Everything's working great - I've tested with multiple clients and clients that get a lock and crash... My question is if it's really necessary to block when you're just trying to release the lock???
Thanks very much,
Jeff
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jeff,
i didn't get need of
"
and the opposite for unlocking:
code:
-----------------------------------------------------------------------
while (unlocked) { wait until locked...}//code to unlock it goes here...notify()
-----------------------------------------------------------------------
"
why you need it? i didn't get why you need to wait for locking, if record is unlocked? in which situation you need above code?
i think you need only
"
code:
-----------------------------------------------------------------------
while (locked) { wait until unlocked...}//code to lock it goes here...notify()
-----------------------------------------------------------------------
"
this part of your code.
regards,
sanjeev.
 
jefferson p
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sanjeev,
I mostly did it for consistency - basically, to have the same, but opposite, functionality as the "lock" method.
The reason it works (the current way) is because an unlock request always is made when the record is already locked (by the client who makes the request) - so it basically never waits anyway... In fact, I can't think of a situation where it wouldn't work...
Thanks,
Jeff
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jefferson, your code looks right. The only question I have is why you need to notify() in your lock method. You only need to notify when you unlock.
Mark
 
jefferson p
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, Mark - I noticed that when I took out the wait for the unlock...
Thanks,
Jeff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic