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?

0


source to share


6 answers


UUID generation is done locally and does not require a live network connection.



+2


source


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.

+2


source


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?

0


source


What is the purpose of these s.substring calls? It looks like you are returning the original string.

0


source


If you are adding 5 rows together over a large dataset, this could be a problem. Try using StringBuffer. Surprisingly, a difference can be achieved by concatenating more than 1-2 rows together, especially for larger datasets.

0


source


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

0


source







All Articles