fix: Remove unnecessary and possibly not threadsafe flag (#1811)

This commit is contained in:
Morteza Adigozalpour 2021-09-07 20:43:47 +02:00 committed by GitHub
parent e2ebb59fe7
commit 3126ad3106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 8 deletions

View File

@ -36,16 +36,12 @@ public final class ThreadSafeDoubleCheckLocking {
private static volatile ThreadSafeDoubleCheckLocking instance;
private static boolean flag = true;
/**
* private constructor to prevent client from instantiating.
*/
private ThreadSafeDoubleCheckLocking() {
// to prevent instantiating by Reflection call
if (flag) {
flag = false;
} else {
if (instance != null) {
throw new IllegalStateException("Already initialized.");
}
}

View File

@ -34,9 +34,7 @@ public final class ThreadSafeLazyLoadedIvoryTower {
private ThreadSafeLazyLoadedIvoryTower() {
// Protect against instantiation via reflection
if (instance == null) {
instance = this;
} else {
if (instance != null) {
throw new IllegalStateException("Already initialized.");
}
}