fix: Remove unnecessary and possibly not threadsafe flag (#1811)
This commit is contained in:
parent
e2ebb59fe7
commit
3126ad3106
@ -36,16 +36,12 @@ public final class ThreadSafeDoubleCheckLocking {
|
|||||||
|
|
||||||
private static volatile ThreadSafeDoubleCheckLocking instance;
|
private static volatile ThreadSafeDoubleCheckLocking instance;
|
||||||
|
|
||||||
private static boolean flag = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* private constructor to prevent client from instantiating.
|
* private constructor to prevent client from instantiating.
|
||||||
*/
|
*/
|
||||||
private ThreadSafeDoubleCheckLocking() {
|
private ThreadSafeDoubleCheckLocking() {
|
||||||
// to prevent instantiating by Reflection call
|
// to prevent instantiating by Reflection call
|
||||||
if (flag) {
|
if (instance != null) {
|
||||||
flag = false;
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Already initialized.");
|
throw new IllegalStateException("Already initialized.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,7 @@ public final class ThreadSafeLazyLoadedIvoryTower {
|
|||||||
|
|
||||||
private ThreadSafeLazyLoadedIvoryTower() {
|
private ThreadSafeLazyLoadedIvoryTower() {
|
||||||
// Protect against instantiation via reflection
|
// Protect against instantiation via reflection
|
||||||
if (instance == null) {
|
if (instance != null) {
|
||||||
instance = this;
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Already initialized.");
|
throw new IllegalStateException("Already initialized.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user