RFR (S): CR 8005926: (thread) Merge ThreadLocalRandom state into java.lang.Thread

Aleksey Shipilev aleksey.shipilev at oracle.com
Tue Jan 15 14:38:58 UTC 2013

On 01/15/2013 06:33 PM, Peter Levart wrote:
> One more thing, not related to serialization:
> If a TLR reference is somehow passed from the thread that obtained it
> via TLR.current() to some other thread that did never call TLR.current()
> and this other thread calls methods on such instance (nextInt(), ...),
> it will start the random sequence from the zero seed, bypassing
> localInit() call...
> Is this ok?

I think this counts as "accidental" sharing, and Javadoc recommends to
always do TLR.current().* to take the appropriate TLR; hence I think
this is the adopted failure scenario. The upside for *not* fixing this
is skipping the initialized checks from each of next*() methods, which
are needed in corner cases only, thus saving the hot-path performance.


More information about the core-libs-dev mailing list