Originally posted by GD Deepz:
What do you all think of a Timer Thread as an inner class in the Data class that checks locked records every 5 mins. If any of the locked records have been locked for more than, say 20 secs, the record is unlocked by calling the unlock().
We can use this idea if a client loses communication with the server for example it gets a RemoteException. Although my client never calls the lock/unlock methods directly and I put the lock/unlock in a try/catch/finally, I could sill have an orphan lock.
As such, there is no need for WeakHashMap or java.server.rmi.Unreferencd
SCJP 1.4, SCJD
Originally posted by peter wooster:
[QB]
A problem with that solution is communicating the fact that you have unlocked a record back to the client. If the client eventually tries to unlock the record they will get a SecurityException if they haven't been informed.[QB]
SCJP 1.4, SCJD
Originally posted by Frans Janssen:
I am doing something very similar. I schedule a new TimerTask for every locked record, that will automatically unlock the record if it is not unlocked by the client within an reasonable amount of time. I still have to decide what "a reasonable amount of time is", but I'll probably take something around 60 seconds.
The Unreferenced solution cannot solve clients that fail to unlock for reasons other than a lost connection.
As an extra, the timer solution also provides a way out of deadlock situations, although I must confess it is not a very elegant one![]()
For the assignment though I am assuming that it will be good enough.
Frans.
MCP (C# application dev 70-316) 860<br />SCJP 1.4 100% SCJD (URLyBird) 378<br />MAD 100% nuts
Originally posted by Inuka Vincit:
I am going with what peter said as well. The Unreferenced is the best sollution, as well as the simplest. The thing is frans there should not be any case other than lost connections to cause orphan locks( crash, power faliure etc should also cause lost connection). IMHO with the timer sollution unless you attempt to notify the client of a timeout your going to leave the client hanging.
SCJP 1.4, SCJD
SCJP 1.4<br />SCJD 1.4
Originally posted by Frans Janssen:
In the end the main reason to choose for the TimerTask is that I do not have to come up with a separate solution to deadlocks. (But then again, if your assuming your clients are the only ones, you can just design your clients such that they will never cause deadlock.*)
Originally posted by Josh Allen:
I think you could eliminate any possible deadlock by only allowing clients to hold a lock on one record at a time. Otherwise two different clients could obviously aquire multiple locks in different sequences and reach deadlock.
Originally posted by Daniel Simpson:
How do you handle orphan locks using sockets?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse:
Hi Daniel,
When the client disconnects you should get a java.net.SocketException (the cause will be "Connection reset"). You can catch that and clear any orphaned locks at that point.
Regards, Andrew
SCJP 1.4<br />SCJD 1.4
Consider Paul's rocket mass heater. |