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

ckozak pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 9a77869632991e07d623ab405c9736eabdfdfd64
Author: Mike Glazer <[email protected]>
AuthorDate: Fri Jun 4 08:17:22 2021 -0700

    LOG4J2-3103: Make listeners in LoggerContext a CopyOnWriteArrayList (#508)
    
    This particular case fails quite often in integration tests
    where you have multiple separate threads potentially creating
    and destroying the singleton LoggerContext independently.
    
    Since this is a Listener List, it makes sense to just make
    it a CopyOnWriteArrayList, since the frequency of both
    occurring is going to be roughly equivalent.
    
    Co-authored-by: Mike Glazer <[email protected]>
---
 .../src/main/java/org/apache/logging/log4j/core/LoggerContext.java    | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index cdc5f86..5e11e0c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -22,9 +22,7 @@ import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
@@ -178,7 +176,7 @@ public class LoggerContext extends AbstractLifeCycle
         if (listeners == null) {
             synchronized(this) {
                 if (listeners == null) {
-                    listeners = Collections.synchronizedList(new 
ArrayList<LoggerContextShutdownAware>());
+                    listeners = new 
CopyOnWriteArrayList<LoggerContextShutdownAware>();
                 }
             }
         }

Reply via email to