Why is my UUID taking too long?
String s = UUID.randomUUID().toString();
return s.substring(0,8) + s.substring(9,13) + s.substring(14,18) +
s.substring(19,23) + s.substring(24);
I am using UDID JDK1.5 but it is using too much time when I connect / disconnect from the network.
I think the UUID might want to access some network.
Can anyone help me?
Quote the API odc :
public static UUID randomUUID()
Static factory for getting UUID type 4 (pseudo-randomly generated). The UUID is generated using a cryptographically strong pseudo-random number generator.
The delay is probably due to the initialization of a cryptographically strong RNG - it will take some time and may even depend on having a network connection as a source of entropy. However, this should only happen once while the JVM is running. However, I don't see a way to solve this problem.
source to share
The javadoc for the UUID http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html has good information on how the UUID is generated. It uses time and clock frequency to generate UUIDs. As Sharptooth says, no network interface is required. Perhaps there is another parallel process that can cause this problem?
source to share
For older versions of Java (probably 6 and earlier) there is a bug in Random that causes it to iterate over the entire temp folder. We've seen generation seeds take 10 minutes on some very bad build machines at NVIDIA. You might want to check the size of your temporary directory.
Compare: http://www.docjar.com/html/api/sun/security/provider/SeedGenerator.java.html To: http://www.java2s.com/Open-Source/Java-Document/6.0-JDK -Modules / j2me / sun / security / provider / SeedGenerator.java.htm
source to share