I am asking this question because of following observations
getting this stack trace in thread dump in highly multi threaded environment
"http-80-200" daemon prio=10 tid=0x00002aaab4981000 nid=0x7520 waiting \ for monitor entry [0x000000004fec7000] java.lang.Thread.State: BLOCKED (on object monitor) at java.security.SecureRandom.nextBytes(SecureRandom.java:433) - waiting to lock <0x00000000c00da220> (a java.security.SecureRandom) at java.util.UUID.randomUUID(UUID.java:162)
found this link
http://bugs.sun.com/view_bug.do?bug_id=6611830
if UUID is not thread safe, please suggest any other library if it exist.
In fact, all collection classes (except Vector and Hashtable) in the java. util package are not thread-safe. The only two legacy collections are thread-safe: Vector and Hashtable.
Its slower than Random, but much more secure. Take a look at the source code for UUID a few posts up, its already using a secureRandom. It is using SecureRandom, but it is removing some of the randomness.
Well, the source code shows UUID. randomUUID uses SecureRandom . As you can see, you can use either, but in a secure UUID you have 6 non-random bits, which can be considered a disadvantage if you are picky.
The third static method returns a UUID object given the string representation of a given UUID: UUID uuid = UUID. fromString(String uuidHexDigitString); Let's now look at how a UUID is structured.
UUID is immutable so it's potentially thread safe, but apparently there was some evil caching going on in some accessors that made it unsafe (that bug is fixed now).
But your thread dump just says that a thread is waiting for a lock at SecureRandom.nextBytes
, which is used by the UUID.randomUUID
factory, which definitely is thread-safe. It's what's supposed to happen when several threads call it simultaneously, as far as I can tell.
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