[#5720] Static initializers can cause deadlock
Motivation: SystemPropertyUtil requires InternalLoggerFactory requires ThreadLocalRandom requires SystemPropertyUtil. This can lead to a dead-lock. Modifications: Ensure ThreadLocalRandom does not require SystemPropertyUtil during initialization. Result: No more deadlock possible.
This commit is contained in:
parent
8d1e46ffd1
commit
e4154bcb0b
@ -66,8 +66,7 @@ public final class ThreadLocalRandom extends Random {
|
|||||||
|
|
||||||
private static final AtomicLong seedUniquifier = new AtomicLong();
|
private static final AtomicLong seedUniquifier = new AtomicLong();
|
||||||
|
|
||||||
private static volatile long initialSeedUniquifier =
|
private static volatile long initialSeedUniquifier;
|
||||||
SystemPropertyUtil.getLong("io.netty.initialSeedUniquifier", 0);
|
|
||||||
|
|
||||||
private static final Thread seedGeneratorThread;
|
private static final Thread seedGeneratorThread;
|
||||||
private static final BlockingQueue<Long> seedQueue;
|
private static final BlockingQueue<Long> seedQueue;
|
||||||
@ -75,11 +74,18 @@ public final class ThreadLocalRandom extends Random {
|
|||||||
private static volatile long seedGeneratorEndTime;
|
private static volatile long seedGeneratorEndTime;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
initialSeedUniquifier = AccessController.doPrivileged(new PrivilegedAction<Long>() {
|
||||||
|
@Override
|
||||||
|
public Long run() {
|
||||||
|
return Long.getLong("io.netty.initialSeedUniquifier", 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (initialSeedUniquifier == 0) {
|
if (initialSeedUniquifier == 0) {
|
||||||
boolean secureRandom = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
boolean secureRandom = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean run() {
|
public Boolean run() {
|
||||||
return SystemPropertyUtil.getBoolean("java.util.secureRandomSeed", false);
|
return Boolean.getBoolean("java.util.secureRandomSeed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user