44 |
|
private long rnd; |
45 |
|
|
46 |
|
/** |
47 |
< |
* Initialization flag to permit the first and only allowed call |
48 |
< |
* to setSeed (inside Random constructor) to succeed. We can't |
49 |
< |
* allow others since it would cause setting seed in one part of a |
50 |
< |
* program to unintentionally impact other usages by the thread. |
47 |
> |
* Initialization flag to permit calls to setSeed to succeed only |
48 |
> |
* while executing the Random constructor. We can't allow others |
49 |
> |
* since it would cause setting seed in one part of a program to |
50 |
> |
* unintentionally impact other usages by the thread. |
51 |
|
*/ |
52 |
|
boolean initialized; |
53 |
|
|
69 |
|
|
70 |
|
/** |
71 |
|
* Constructor called only by localRandom.initialValue. |
72 |
– |
* We rely on the fact that the superclass no-arg constructor |
73 |
– |
* invokes setSeed exactly once to initialize. |
72 |
|
*/ |
73 |
|
ThreadLocalRandom() { |
74 |
|
super(); |
75 |
+ |
initialized = true; |
76 |
|
} |
77 |
|
|
78 |
|
/** |
93 |
|
public void setSeed(long seed) { |
94 |
|
if (initialized) |
95 |
|
throw new UnsupportedOperationException(); |
97 |
– |
initialized = true; |
96 |
|
rnd = (seed ^ multiplier) & mask; |
97 |
|
} |
98 |
|
|