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

B&S logical record locking

 
Bob Stone
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am preparing the B&S project, and encountering the understanding of locking, as the requirement specified that:



If just let the current thread keep waiting until the target record is released, it may be blocked very long time as the user holding the target record probably leaves for a day and then be back to continue record updating (what the one to do is so simply just to press the confirm button).
So I prefer to add a timestamp to the record reservation entry in which there are record no, owner Id (cookie), timestamp. If a (logical) locked record is pending more than 2 mins (time out), another thread to acquire the record will grant the right to lock it. This design can also serve the issue of client crashes.

But the requirement said that SHOULD cause the current thread to give up the CPU...., now my question is can I use the time out approach or not ?

Thanks
[ May 19, 2007: Message edited by: Barry Gaunt ]
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bob,

I think you have to call wait in a synchronized block and the synchronized block contains the "waiting-while loop". Such "waiting-while loop" is pretty common in the multi-threading in case several threads try to access the same resources.

In my assignment a timeout is not required. So it is up to you, if you want to implement a timeout on a lock.
 
Muhammad Shafique
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bob,
I had same requirement in my assignment. It's better to stick to the requirement. If client crash handling is not required, there is no need to implement it. If a record is already locked, next requesting thread should wait until it is notified.

Shafique
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people,

This theme was enough discussed here, just make a search over "Time out" and you'll get a plenty of answers. My advice is don't use it (at least if you are not explicit asked for) - this will bing you less problem in the future.

A few pro (not to do it) argument :
1.nobody ask for it - it was your deduction.
2.make the test more complex - and the chance that some error is bigger
3.you must make the DAO layer and its clients to follow some constraints (the time out rule) - even more you harcode this rules in your lock manager - so you lose some flexibility.
4.there are also other way to interrupt a waiting thread - just steep on tis tail .

A few against (do it) argument :
1.you can prevent a death lock situation


Regards,
M
 
Bob Stone
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,
I will keep my design as simple so easily to be implemented and tested.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic