-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
StatusLogger
instance lazy
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,7 +293,20 @@ private static Properties readPropertiesFile() { | |
} | ||
} | ||
|
||
private static volatile StatusLogger INSTANCE = new StatusLogger(); | ||
/** | ||
* Wrapper for the default instance for lazy initialization. | ||
* <p> | ||
* The initialization will be performed when the JVM initializes the class. | ||
* Since {@code InstanceHolder} has no other fields or methods, class initialization occurs when the {@code INSTANCE} field is first referenced. | ||
* </p> | ||
* | ||
* @see <a href="https://www.infoworld.com/article/2074979/double-checked-locking--clever--but-broken.html?page=2">Double-checked locking: Clever, but broken</a> | ||
*/ | ||
private static final class InstanceHolder { | ||
|
||
private static volatile StatusLogger INSTANCE = new StatusLogger(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vy
Author
Member
|
||
|
||
} | ||
|
||
private final Config config; | ||
|
||
|
@@ -351,7 +364,7 @@ public StatusLogger( | |
* @return the singleton instance | ||
*/ | ||
public static StatusLogger getLogger() { | ||
return INSTANCE; | ||
return InstanceHolder.INSTANCE; | ||
} | ||
|
||
/** | ||
|
@@ -363,7 +376,7 @@ public static StatusLogger getLogger() { | |
* @since 2.23.0 | ||
*/ | ||
public static void setLogger(final StatusLogger logger) { | ||
INSTANCE = requireNonNull(logger, "logger"); | ||
InstanceHolder.INSTANCE = requireNonNull(logger, "logger"); | ||
} | ||
|
||
/** | ||
|
is
volatile
needed in this case?