Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock Cookie Generation

 
Wickes Potgieter
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, just wondering...

in my lockRecord method, what will be the best way to generate this value for the cookie?

Thank you!
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO static counter ensures that there will be no same cookies. But I didnt use cookies at all and cannot tell which way is better.
[ June 07, 2004: Message edited by: Denis Spirin ]
 
Wickes Potgieter
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply!

If I may ask, how did you handle the locking without using the cookies?
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Server-side) booking method looked like this:




In lock manager I used standard lock(), unlock() (wait() until notified if record is booked, etc) with HashMap holding ID-recNo pairs, but as ID i used object returned by Thread.currentThread().
Thus we have no deadlocks (due to dead clients) and increase of performance because there is no need to pass cookie to client. However, both lock and unlock must be called from the same method because only then it is guaranteed that client id wont change.
[ June 07, 2004: Message edited by: Denis Spirin ]
 
Wickes Potgieter
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you specified a dummy value for the lockCookie parameter when you called the unlock method on the Data class?

Also, did you mentioned this in your design choices doc?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wickes,

I assume you specified a dummy value for the lockCookie parameter when you called the unlock method on the Data class?

Also, did you mentioned this in your design choices doc?


There are multiple versions of each assignment. Probably Denis got a version without lock cookies.

To reply to your first question ("what will be the best way to generate this value for the cookie?"), Random.nextLong() is perfect. A few people here think (but I don't) that generating unique cookie values is better. In case you'd think that too, you can still put the currently-in-use cookies in a Set.

Regards,

Phil.
[ June 08, 2004: Message edited by: Philippe Maquet ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic