This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I used System.nanoTime(), but of course you can use the Random class and use the nextLong() method. Or you can use both and multiply both results with each other. But i think System.nanoTime() should do the job. You can always add something to your choices.txt that generation cookie logic can be refined (extended) in a future release...
Another question about it: What should I do when someone try lock an ID that already looked ?? My inteface only throw RecordNotFoundException ? Should I throw one database runtime exception ? What did you do Roel ??
Thanks again Roel.... I'm sure that I wont comit the Laura mistake.
About SecurityException in unlock method. Can I throw it if passed a recordNumber that wasn't locked or if passed a wrong cookie value ?
You can certainly throw it if a wrong cookie value is passed, because I believe that is exactly why the SecurityException exists. But a record that is not locked, is a subtle difference.
In my assignment I had no SecurityException, so I throw in both situations an IllegalStateException.
In this thread someone asked the same question like you.
I'm writting choice.txt and I need put 'why' I choose System.nanoTime() to generate locke cookie.
I'm actually did cause you guys suggest for me.... And it really work !
Could you help me please ?