I`m using RMI to handle the networking part, but where would i need to implement the code for a crashed client.
I create a new Database object for each client. and then when they change any data the record gets locked...
but now what is the client times out and the record does`nt get unlocked?? where can i implement this? i thought about adding a timeout, but is there a way to say if timeout then do this... or finally ???
However it can be an interesting exercise to try and work out how to do it, and it is certainly something you would want to think about in real life.
Depending on your instructions, you may not be able to have a timeout value for how long a lock may be kept. You will have to check your instructions to see whether you can or not.
The other things you can think about are:
Since you have a Database object per client, I assume you are using the Database object as the key in your collection of owned locks. In which case you might want to use a WeakHashMap as the collection - if the remote client disconnects (or crashes) there will no longer be a remote reference to the Database object, so it will be automagically removed from the WeakHashMap (after RMI's lease value expires + garbage collector runs). Almost a no brainer solution. (You may want to create a separate daemon thread to monitor when locks disapear and notifyAll waiting threads that a lock has gone).
Alternatively you might want to have your per-client remote object implement the Unreferenced interface. If you do this then when the remote client disconnects (or crashes) then the unreferenced() method in that instance of the remote object will be run (after RMI's lease value expires + garbage collector runs) and you can manually clean up any locks.