• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Lock Cookie Generation

 
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!
 
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?
 
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 ]
 
Die Fledermaus does not fear such a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic