Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock / Unlock and a dead thread question

 
Donald Wedding
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?
 
R Bischof
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
 
kerry shih
Greenhorn
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!
Kerry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic