I believe I may have found a UUID multi-threading bug in Oracle Java7 Update 5 and I was wondering if anyone could confirm with an independent example. Basically what happens is if I call UUID.Random() concurrently (I'm using 64 threads), I get a collision quickly most of the time).
However, If the UUID generator is warmed up by running a test beforehand that just tosses a bunch of UUIDs it seems to work fine. Here's a gist in scala:
https://gist.github.com/3318973
Important to note that I'm inserting into a mutable Set that I'm synchronizing from 64 different threads. The main thread blocks waiting for the workers to finish and then checks that the set size is what it should be. Collisions are printed as they occur.
thanks! Adam
Class UUID. A class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value. There exist different variants of these global identifiers.
UUIDs are fixed length. UUIDs are 128-bits in binary. (32 hex digits x 4 bits per hex digit = 128-bits).
A collision is possible but the total number of unique keys generated is so large that the possibility of a collision is almost zero. As per Wikipedia, the number of UUIDs generated to have atleast 1 collision is 2.71 quintillion. This is equivalent to generating around 1 billion UUIDs per second for about 85 years.
The randomUUID() method is used to retrieve a type 4 (pseudo randomly generated) UUID. The UUID is generated using a cryptographically strong pseudo random number generator.
It could be this:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7071826
It's fixed in 7u6, which should be out soon.
I did a quick check with Java 1.7.0_05 (no scala or scalatest involved) and could not reproduce any UUID collisions whatsoever. My basic setup is the same, with 128 threads throwing 10000 uids at a synchronized set each. This is very likely an issue with your testcode, which i can't doublecheck on this machine atm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With