• 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 issue

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I am confused about how to implement the locking mechanism for my assignment. I have the following signature:

public long lock(int recNo)
public void unlock(int recNo, long cookie)

Should I consider the cookie as the client id?
Please help me out.
Thanks
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the comments on the lock method in the interface Sun gave you.

Charlie
 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My assignment is difference from yours, but the locking was similar, I used a HashMap to store the locked records, according to your situation, the key should be the cookie, the value should be the locked record (record number), some people used a LockManager, i think that is a better way, I only got 44 out of 80 about locking
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In reply to: HaoZhe XU


the key should be the cookie, the value should be the locked record (record number)



Eh? The record is unique, only one client can lock a specific record at a time, that is rather the whole point.
Although the cookie is probably best unique, this is not a requirement and nothing disastorous is going to go wrong if it isn't.
Surely this means that it is better if the recNo is the key.

Glad you mentioned your 44/80, I will upgrade to LockManager, did you not implement timeouts on cookies?
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic