a. since the verify(recNo) method may throw a RecordNotFoundException in the block, the notifyAll() method will not be called then. Would that be a problem for other threads wait for the reservedRecords object? Should I put the notifyAll() method into a finally block?
b. The InterruptedException may be thrown by the wait() method, how should I deal with the exception? In server side or client side?
Two threads try to lock a record. The first thread deletes the record. What happens to the other thread?
In that case you have to ensure that the record is unlocked after the delete occurs. So you might want to consider breaking your current unlock() method into two parts - one part which can do the verification on whether the record is valid or not, and another (private method) part which does the actual unlocking and calls notifyAll(). So delete() could then call that private method.
Don't forget to check if a record still exists after you acquired the lock.
Otherwise, you will get the lock on the record which doesn't exist.
In your code, would there be a problem if a exception is thrown in your lock(); and in fact the lock() didn't lock. Then your finally will be executed anyway, unlocking another thread's lock? Is that possible? In my implementation of lock/unlock, I used a static vector, I think it would be a problem for mine.