Review Request : 7071826 : Avoid benign race condition in initialization of UUID

Mike Duigou mike.duigou at
Thu May 10 23:11:30 UTC 2012

Hello all;

A benign but potentially expensive race condition was discovered in java.util.UUID. The initialization of numberGenerator may cause the creation of a number of SecureRandom instances if multiple threads are attempting to initialize the field at the same time. This can happen because creation of the SecureRandom instances, depending upon system configuration and state, may take a significant amount of time.

Using a shared SecureRandom instance for the numberGenerator is an optimization--nothing bad happens as a result of each thread using it's own instance. However, creation of multiple SecureRandom instances, especially during system startup, may be expensive or have high latency if no previous SecureRandom instances have been created.

Accordingly, a holder class is used to ensure that only a single SecureRandom instance is created. The holder also serves to defer initialization of numberGenerator until randomUUID() is first called. 


This issue will be proposed for backport to Java 7u6 once integrated into Java 8



More information about the core-libs-dev mailing list