• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Lock / Unlock and a dead thread question

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I handle this (although I doubt I would need to for the SCJD exam), but how do I handle this anyways?
Thread "A" Locks record 1.
Thread "B" tryies to lock record 1, but must wait()
Thread "A" dies a horrible, agonizing death.
How does "B" figure out thread "A" is dead?
How does the server figure out "A" is dead and unlock the record?
By the way, do I need to handle this on the SCJD exam?
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Donald,
this is not really a threading issue as these operations are usually performed within separate client calls and thus by different threads.
If you want a more bullet-proof approach you may use one remote DataSession per client. This DataSession object may provide the same services as the Data class and has thus a similar interface.
As soon as a client dies the distributed garbage collector makes it's server side DataSession eligibla for garbage collection. In the DataSession's finalize method you can remove all locks held by this session.
There have been some threads around reagrding this design.
Although it does not really help here because the second client will have to wait for the lock until the DataSession of the first client has been garbage collected. But it makes the design clear and ensures that dead locks won't live forever.
My $0.02
Rainer
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like your solution. I have a question though. If a remote client dies wouldn't your server side impl not necessarily be notified? I was thinking about a timeout mechanism that would insure that records wouldn't lock forever.
Either way this is not a requirement so Ill probably let it go. There's better ways of scoring points!
Kerry
 
Your mother is a hamster and your father smells of tiny ads!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic