• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Locking for URLyBird 1.1.1

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic