File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Lock timeout 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 "Lock timeout" Watch "Lock timeout" New topic
Author

Lock timeout

Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
What is everyone's opinion for a timeout period on a lock? Right now, I'm using 5 seconds which seem adequate but I'm not sure. Also should the owner of the lock be notified that the lock has been released after timing out? Do we just assume that the owner of a timed out thread has died? As I see it right now there is only a slight chance of data corruption if for some chance the owner of the timed-out lock is still alive.
Thanks,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello Michael:
Why do you need timeout? Am I missing anything really good? I did not see any requirement on this? I did not use it.
My bottom line was their requirement which I really liked it, loved it. ...A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is little more efficient than the simple choice.
It was my assumption that server crash, unpredictable clients, and unpredictable network
connections are not issues. So, I did not handle such extreme situation in SCJD's application.
What do you think? Does it sound good?
-Bal
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Bal,
I see your point, but my timeout scheme consists of one interface, LockTimerCallback with one method which is implemented by my LockManager, and a LockTimer class which extends TimerTask and consists of less than 40 lines of code for the whole class. I feel the design is clear enough for a junior programmer to understand and maintain. I do respect your opinion and hope you continue to respond to my posts.
Thanks,
Michael Morris
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

I have seen a few with timeouts, and it is a fine design. I would put it to a minute, just to be safe.
Most others have used the Unreference interface to handle stale clients, but a timeout feature is fine. Especially if it is implemented simply that that junior programmer can understand.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Thanks Mark. Do you think using a roll-your-own callback scheme is OK? I thought about using a beans scheme (firePropertyChange or fireVetoableChange) but that would have been more complex than what I did. The plus side would be that it's built into the API.

Thanks again,
Michael Morris
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Do you think using a roll-your-own callback scheme is OK?

Well, you could always implement the Observable interface so that you can make your own callback scheme. The big question is can that Junior Programmer understand it?
Mark
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
..I feel the design is clear enough for a junior programmer to understand and maintain...
Hello Michael:
I think you are in right track. Now I believe, it is not complex too, Keep it up. And OH YEAH! I will try to respond everybody's posting as much as I can.
-Bal
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Thanks Bal,
It's always nice to have the opinion of someone whose already made it to the top of the mountain.
You and Mark have already helped me fix some shortcomings in my initial design. I'm sure I will use your expertise again before I finish.
Thanks again
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lock timeout