aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes culling dead locks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "culling dead locks" Watch "culling dead locks" New topic
Author

culling dead locks

Debra Bellmaine
Ranch Hand

Joined: Feb 22, 2002
Posts: 40
Howdy All,
I'm storing locks in a HashMap that contains recordNum and Connection instance pairs. RecordNum is the key in the map.
I want some opinions on whether or not I should be concerned with clients who have died an untimely death after locking a record and before unlocking it. (Pardon any puns.)
Is this important? What are some options for implementing?
2nd issue. If I have two clients up and 2nd client is waiting to obtain record lock, my client is unresponsive. I've thought about putting the client's booking logic into a separate thread, but my current logic can throw several exceptions and I couldn't see how to handle this in a separate thread, since I can't change the signature of run() by adding a "throws" clause. This is probably dumb and has an easy solution.
Any thoughts on either issue?
Thanks,
Debra


...I get by with a little help from my friends...
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Implement Unreferenced interface in your Connection object and let the 2nd client wait until the lock is released. This is an easy choice. In addition to it, you can spawn a thread to wake up every few seconds and cleanup those unused locks. That way the 2nd client waits only for few seconds of your choice.
[ May 27, 2002: Message edited by: Sai Prasad ]
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
If you depend on Unreferenced.unreferenced() alone, you will have to wait for java.smi.dgc.leaseValue to expire and for the sun.rmi.dgc.checkInterval time to pass. The defaults for these two are 600000ms and 300000ms, respectively. To set them low enough to be usefull for users of your application, they would need to be set so low (perhaps 10000 and 5000 ms) that you would have extra network traffic from your remote object leases being renewed, and some extra load on the server's JVM from checking for expired leases. I don't know how much though, but I would definitely look into it.
I like Sai's idea of a thread that checks every few seconds, but I am unsure how this would be viewed by the graders since crashed clients are not mentioned in the requirements. Maybe someone who got a high score and also did something like this will speak up.
-BJ
[ May 27, 2002: Message edited by: BJ Grau ]
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
In my submission, I did spawn a custom thread to clean up unreferenced locks and got 51/53. I also remember reading a post with high marks using custom thread. It is up to you.
Debra Bellmaine
Ranch Hand

Joined: Feb 22, 2002
Posts: 40
Sai,
I like the idea of the separate thread, in addition to Unreferenced. Did you spawn the thread from your LockManager (if you used one)?
How did you check that the locks were unused?
Debra
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Debra:
Yes. I spawned the thread from the LockManager. In fact the Thread class is an inner class of LockManager. I record the time when the lock was made using another object called Lock which contains the Timestamp. I compare the current time and the locked time and if it is more than certain seconds (you need to pick this one), I remove the lock using the cleanup thread.
[ May 28, 2002: Message edited by: Sai Prasad ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: culling dead locks