Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3126ad3

Browse files
authored
fix: Remove unnecessary and possibly not threadsafe flag (iluwatar#1811)
1 parente2ebb59 commit3126ad3

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

‎singleton/src/main/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLocking.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ public final class ThreadSafeDoubleCheckLocking {
3636

3737
privatestaticvolatileThreadSafeDoubleCheckLockinginstance;
3838

39-
privatestaticbooleanflag =true;
40-
4139
/**
4240
* private constructor to prevent client from instantiating.
4341
*/
4442
privateThreadSafeDoubleCheckLocking() {
4543
// to prevent instantiating by Reflection call
46-
if (flag) {
47-
flag =false;
48-
}else {
44+
if (instance !=null) {
4945
thrownewIllegalStateException("Already initialized.");
5046
}
5147
}

‎singleton/src/main/java/com/iluwatar/singleton/ThreadSafeLazyLoadedIvoryTower.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public final class ThreadSafeLazyLoadedIvoryTower {
3434

3535
privateThreadSafeLazyLoadedIvoryTower() {
3636
// Protect against instantiation via reflection
37-
if (instance ==null) {
38-
instance =this;
39-
}else {
37+
if (instance !=null) {
4038
thrownewIllegalStateException("Already initialized.");
4139
}
4240
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp