• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Lock / Unlock and a dead thread question

Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • 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!
Pay attention! Tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic