• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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 ]
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic