Improving ThreadLocalRandom (and related classes) (original) (raw)

Doug Lea dl at cs.oswego.edu
Tue Jan 8 17:33:32 UTC 2013


On 01/08/13 11:07, Chris Hegarty wrote:

Doug,

I have no objection as such to adding certain fields to j.l.Thread to support faster ThreadLocalRandom. Maybe it would help to see how they are to be used?

Sorry, it just occurred to me that you surely meant: how would these Thread fields be used in ThreadLocalRandom. here's the basic plan:

  1. There is a singleton TLR that is always returned by TLR.current after first checking (via nonzero probe) if initialized for this thread.

  2. On a call to next() etc, this object accesses and updates threadLocalRandomSeed using Unsafe (to bypass access control).

-Doug



More information about the core-libs-dev mailing list