Don't Let Hibernate Steal Your Identity
Subject:   Uniqueness and UUID
Date:   2006-09-14 11:21:05
From:   jbrundege
Response to: Uniqueness and UUID

I believe the JUG library Time-based UUID does what you want. It uses the MAC Address and a timestamp, but it uses the filesystem to synchronize the timestamp between all JVM's operating on the same machine.

In case anyone is wondering how a random-based UUID can be considered unique, the random portion of the number is 14 bytes (I believe 2 bytes are reserved to indicate the type of UUID). That's 2^112 combinations. Calculating the odds of a collision is complex math (any takers?), but let's just say the odds are astronomically low. If you wrote a program that did nothing but generate random-based UUIDs, one per millisecond, the time to the first collision would probably be measured in thousands (if not millions) of years! You have to judge for your own requirements, but for most common uses a random-based UUID is absolutely safe, and will never result in a collision.