private int probe ( ) { // Fast path for reliable well-distributed probe, available from JDK 7+. // As long as PROBE is final this branch will be inlined. if ( PROBE != - 1 ) { int probe ; if ( ( probe = UNSAFE . getInt ( Thread . currentThread ( ) , PROBE ) ) == 0 ) { ThreadLocalRandom . current ( ) ; // force initialization probe = UNSAFE . getInt ( Thread . currentThread ( ) , PROBE ) ; } return probe ; } /* * Else use much worse (for values distribution) method: * Mix thread id with golden ratio and then xorshift it * to spread consecutive ids (see Knuth multiplicative method as reference). */ int probe = ( int ) ( ( Thread . currentThread ( ) . getId ( ) * 0x9e3779b9 ) & Integer . MAX_VALUE ) ; // xorshift probe ^= probe << 13 ; probe ^= probe >>> 17 ; probe ^= probe << 5 ; return probe ; }
Returns the probe value for the current thread . If target JDK version is 7 or higher than ThreadLocalRandom - specific value will be used xorshift with thread id otherwise .