• 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(), unlock() and isLocked()

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

In my assignment, the interface has the methods: lock(), unlock() and isLocked(). So I assume they must be used by the client. Is that correct?
If so, I imagine that the client will first call the isLocked() method as a while condition. When the desired record becomes unlocked (the while finish), the client will call the lock() method.
But between the finish of the while, and the call to the the lock() method, another client can get the lock for the record.

How can I ensure that nobody is going to get the lock for the desired record between this two operations? I can't just synchronize in the client...

Thanks!!

_____________________________________________________________________

EDIT: Now, reading more carefully, I noticed the instructions say that the lock method does all this wait-while-is-locked-and-then-lock work.
So, I'll change my question... For what did you guys used the isLocked() method?

Thanks!!
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lucas,

Your more careful reading of the instructions is spot-on: lock-method is indeed responsible for "waiting while record is locked and lock when record is available". The isLocked is not used in my application (just like I didn't use delete and create methods), but I provided an actual (working) implementation for these unused methods.

Hope it helps!
Kind regards,
Roel
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic