Hi Linda & John,
Linda - Sorry to hear you failed.
I know many people have passed (with good scores) without any orphaned lock processing. As per Peter's suggestion, you might want to reconsider your locking strategy to ensure it does meet the requirements (and does not change any requirements). Some things to think about: Do you handle the case where one thread deletes a record
while another thread is waiting for the lock? Do you handle the case where two threads are trying to create a record simultaneously?
As Peter mentions, the unreferenced() method is called when there are no references to a particular remote object. If you use a factory to create one remote object per connected client then unreferenced() will be called when
that particular client disconnects. You will still need some way of tracking which locks are still owned by that particular client though.
Another alternative is to use a WeakHashMap to store the locks / client references (again, this requires a unique remote object per connected client). Any orphaned locks will automatically be removed from the WeakHashMap sometime after the client disconnects (exact timing dependant on lease value). You would also need a separate thread monitoring the expected locks versus the actual number of locks, and call notifyAll() if the two numbers differ.
John - I suspect that your solution will not meet the requirements. Check the wording of the API documentation you were provided - does it imply that you can have a timeout at all? If you can have a timeout, do you think having the timeout on the thread
attempting to aquire the lock is correct?
Regarding the exception thrown - it lists two possible reasons, only one of which is valid. You should reduce your message to show the correct cause.
You also try to aquire the lock before checking whether the record is valid or not. You might want to consider having a separate (private) method to check validity of the record, in which case your code could be reduced to:
The recordIsValid() method can throw the RecordNotFoundException directly.
Also - you really should not have such a long line anywhere in your code. The Sun
Coding Conventions suggest you should
Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools. Regards, Andrew