File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock timeout

 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bal Sharma
Ranch Hand
Posts: 273
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 273
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..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
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic