• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S logical record locking

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all,
I will keep my design as simple so easily to be implemented and tested.
 
Do not set lab on fire. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic