File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes how to design dead lock cleaner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "how to design dead lock cleaner" Watch "how to design dead lock cleaner" New topic

how to design dead lock cleaner

Along huang
Ranch Hand

Joined: Feb 09, 2004
Posts: 72
I create a daemon thread as dead lock cleaner,which will kill a thread having locked database for a minute. But the problem is,How do the Cleaner know the time a thread locking?


SCJP1.4 SCJD 2<br />SCEA(In progressing)
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Hi Along,

I would recommend against having a thread kill off locks that have been hanging around too long. Not only the instructions do not require this, but my reading of the instructions would lead me to believe that the lock would remain valid for as long as my client application wanted it to stay valid.

You may wish to look at the recent topics talking about RMI Connection Factories, and using this in conjunction with either the Unreferenced interface or a WeakHashMap to do dead client cleanups.

If you do want to have a timeout, then you are going to have to have some way of storing the time the lock was granted with the lock itself - possibly have a lock object which holds these details.

Regards, Andrew
[ July 06, 2004: Message edited by: Andrew Monkhouse ]

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Along huang
Ranch Hand

Joined: Feb 09, 2004
Posts: 72
Thank you very much!

I thought over and over, and the conclusion is that I never use dead lock cleaner.

Because my design adopt the optimistic lock, i.e. user can't lock a record when selecting a data row in JTable. for update functionality, I envelop the update() and lock() given by instruction, just provide client program a method executeUpdate() that refer to update() and lock(),
and executeUpdate() run at server side, so never occur dead lock situation.

and I don't use cookie, but I read some guideline book, most of them recommend to use cookie to uniquely identify the locking thread, I am not sure my design at this aspect.

best regards!
I agree. Here's the link:
subject: how to design dead lock cleaner
jQuery in Action, 3rd edition