提交 cc676ae4 编写于 作者: M martin

6955840: ThreadLocalRandom bug - overriden setSeed(long) method is not invoked...

6955840: ThreadLocalRandom bug - overriden setSeed(long) method is not invoked for java.util.Random(long)
Summary: Allow setSeed only during construction
Reviewed-by: dl, dholmes
上级 1c3b2b7f
...@@ -73,10 +73,10 @@ public class ThreadLocalRandom extends Random { ...@@ -73,10 +73,10 @@ public class ThreadLocalRandom extends Random {
private long rnd; private long rnd;
/** /**
* Initialization flag to permit the first and only allowed call * Initialization flag to permit calls to setSeed to succeed only
* to setSeed (inside Random constructor) to succeed. We can't * while executing the Random constructor. We can't allow others
* allow others since it would cause setting seed in one part of a * since it would cause setting seed in one part of a program to
* program to unintentionally impact other usages by the thread. * unintentionally impact other usages by the thread.
*/ */
boolean initialized; boolean initialized;
...@@ -98,11 +98,10 @@ public class ThreadLocalRandom extends Random { ...@@ -98,11 +98,10 @@ public class ThreadLocalRandom extends Random {
/** /**
* Constructor called only by localRandom.initialValue. * Constructor called only by localRandom.initialValue.
* We rely on the fact that the superclass no-arg constructor
* invokes setSeed exactly once to initialize.
*/ */
ThreadLocalRandom() { ThreadLocalRandom() {
super(); super();
initialized = true;
} }
/** /**
...@@ -123,7 +122,6 @@ public class ThreadLocalRandom extends Random { ...@@ -123,7 +122,6 @@ public class ThreadLocalRandom extends Random {
public void setSeed(long seed) { public void setSeed(long seed) {
if (initialized) if (initialized)
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
initialized = true;
rnd = (seed ^ multiplier) & mask; rnd = (seed ^ multiplier) & mask;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册