You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/02/04 03:51:19 UTC

[logging-log4j2] 03/03: Simplify lazy init

This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 003c40b6a30d0933de58be24b66d8325b1e4a691
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Thu Feb 3 20:55:44 2022 -0600

    Simplify lazy init
    
    Signed-off-by: Matt Sicker <ma...@apache.org>
---
 .../apache/logging/log4j/plugins/util/PluginRegistry.java  | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java
index c723cf1..ca4b5f6 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java
@@ -50,8 +50,7 @@ public class PluginRegistry {
 
     private static final Logger LOGGER = StatusLogger.getLogger();
 
-    private static volatile PluginRegistry INSTANCE;
-    private static final Object INSTANCE_LOCK = new Object();
+    private static final Value<PluginRegistry> INSTANCE = LazyValue.forSupplier(PluginRegistry::new);
 
     /**
      * Contains plugins found in Log4j2Plugins.dat cache files in the main CLASSPATH.
@@ -81,16 +80,7 @@ public class PluginRegistry {
      * @since 2.1
      */
     public static PluginRegistry getInstance() {
-        PluginRegistry result = INSTANCE;
-        if (result == null) {
-            synchronized (INSTANCE_LOCK) {
-                result = INSTANCE;
-                if (result == null) {
-                    INSTANCE = result = new PluginRegistry();
-                }
-            }
-        }
-        return result;
+        return INSTANCE.get();
     }
 
     /**