is java.util.UUID thread safe?

前端 未结 2 2051
忘掉有多难
忘掉有多难 2021-02-05 03:47

I am asking this question because of following observations

  1. getting this stack trace in thread dump in highly multi threaded environment

    
    
            
2条回答
  •  心在旅途
    2021-02-05 03:55

    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.

提交回复
热议问题