Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Locking issue

 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
 
Charlie Goth
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the comments on the lock method in the interface Sun gave you.

Charlie
 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • 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
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • 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?
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!