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!
I used a static long and simply increment it from a synchronized method. For example,
Joined: Aug 12, 2003
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
Joined: Dec 25, 2003
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