• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to generate a unique lock cookie

 
Min Huang
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My friend suggested concatenating the recNo with the current time. Sounds like a good idea to me.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Min
Originally posted by Min Huang:
My friend suggested concatenating the recNo with the current time. Sounds like a good idea to me.

If you have time, you might want to take a look at the following thread
Lock question
Good Luck.
 
Xie Ruchang
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this thread
Lock Cookie Generation. Bear in mind, the time can be the same for two consecutive locks due the the granularity of the system time update. So if you generate the cookie based on what you have suggested, you will run into problems by having two identical locks!
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
use a unique Random
Damu
 
Michael Hartman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used a static long and simply increment it from a synchronized method.
For example,

...
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael, if you want to have new ideas of generating a lock cookie then you really want to read the link I have given before. In that Phil clearly explained what we can use as a lock cookie and what not.
Good Luck.
BTW, forgot to say. Welcome to JavaRanch and SCJD forum
 
Xie Ruchang
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
Welcome to the forum! Your method works well! Many people prefer the random approach. I prefer the time approach because it can be used by the server to timeout the locks, in the event a client crashed.
Best Regards,
Frankie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic