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
if UUID is not thread safe, please suggest any other library if it exist.
Source :http://www.dcalabresi.com/blog/java/generate-java-uuid-performance/
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 theUUID.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.