-
Notifications
You must be signed in to change notification settings - Fork 313
Open
Description
design-patterns-java/src/refactoring_guru/singleton/example/thread_safe/Singleton.java
Lines 43 to 52 in 7601425
Singleton result = instance; | |
if (result == null) { | |
synchronized (Singleton.class) { | |
result = instance; | |
if (result == null) { | |
instance = result = new Singleton(value); | |
} | |
} | |
} | |
return instance; |
Why do you prefer this overcomplicated code instead of concise, simple, thread-safe, and lazy enough
private static final Singleton instance = new Singleton();
?
Metadata
Metadata
Assignees
Labels
No labels