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

Locking ???

 
Talib Ali
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

i've B&S assignment. I'm facing problem in locking. Sorry this may be a very basic question for many of you.

i dont want to use java.util.concurrent.locks.

I dont know how is it possible when i call lockRecord(RecNo) method and it locks the code/method(s) coming after it. what should i've to write in this method because its looking me difficult with "Sysnchronize". Suppose if i use "Sysnchronize" in lockRecord method then how it will unSysnchronize in unlock method.

Thanks! in advance
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you synchronize multiple methods of a certain object using that object's intrinsic lock, you can call these methods an arbitrary number of times in an arbitrary order from within a synchronized block of code running in the thread that holds the lock, because the intrinsic lock is re-entrant. However, why would you want to call the unlock method from within the synchronized body of the lock method?

Setting, releasing a checking of database level locks should all be performed from within the same syncrhonized context to ensure that all threads trying to perform an action that requires a database level lock will see the appropriate state of that lock and updates to the lock's state aren't "lost", because no two threads can "simultaniously" alter the lock's state. Keeping track of which thread holds a particular database level lock is beyond the scope of the basic synchronization mechanism.
[ March 17, 2008: Message edited by: Jelle Klap ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic