Random over ThreadLocalRandom

后端 未结 6 1853
梦谈多话
梦谈多话 2020-12-02 22:48

Instances of java.util.Random are threadsafe. However, the concurrent use of the same java.util.Random instance across threads may encounter contention an

6条回答
  •  抹茶落季
    2020-12-02 23:16

    Well, if you use the same data structure over multiple threads it has usually to be synchronized. This is expensive and needs time. A ThreadLocalRandom does not have to be synchronized as it is only used by one thread.

提交回复
热议问题