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

This commit is contained in:
Morteza Adigozalpour authored and GitHub committed 2021-09-07 21:43:47 +03:00
1 parent e2ebb59fe7
commit 3126ad3106
2 files changed
+2 -8

No files matched your search

@@ -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.");
} }
} }