• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lock(), unlock() and isLocked()

 
Lucas cotta
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!!
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic