File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes how to generate a unique lock cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "how to generate a unique lock cookie" Watch "how to generate a unique lock cookie" New topic
Author

how to generate a unique lock cookie

Min Huang
Ranch Hand

Joined: Mar 17, 2004
Posts: 100
My friend suggested concatenating the recNo with the current time. Sounds like a good idea to me.


SCJP 1.4, SCJD 1.4, SCBCD (Preparing!)
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
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

Joined: Dec 25, 2003
Posts: 160
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

Joined: Feb 26, 2003
Posts: 240
Hi,
use a unique Random
Damu
Michael Hartman
Greenhorn

Joined: Feb 01, 2004
Posts: 11
I used a static long and simply increment it from a synchronized method.
For example,

...
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
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

Joined: Dec 25, 2003
Posts: 160
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
 
I agree. Here's the link: jrebel
 
subject: how to generate a unique lock cookie