Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking for URLyBird 1.1.1

 
Priya Patra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done same as you but stuck in testing. Did you find anything after your post which you can share??

Thanks

BTW: Your assignment is same as mine URLyBird 1.1.1
[ April 27, 2007: Message edited by: Ken Boyd ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic