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