The DB interface I have has the following signatures for lock and unlock method public long lock(int recNo) throws RecordNotFoundException; public void unlock(int recNo, long cookie) throws RecordNotFoundException, SecurityException; My implementation for lock is something as below
while (reservations.containsKey(recno)) { lockReleased.await(); } lockCookie = (new Date()).getTime() + recno; reservations.put(recno, lockCookie);
My unlock method reads somehting like if (reservations.get(recno) == lockCookie) { reservations.remove(recno); lockReleased.signal(); }
Where reservations is a Hashmap and lockReleased is lock.newCondition() where lock is a reentrantlock.
Can you help me find any flaws here? Thanks for all your help.