• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Lock question

 
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
 
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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic