You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ck...@apache.org on 2021/06/04 15:31:43 UTC
[logging-log4j2] 01/02: LOG4J2-3103: Make listeners in
LoggerContext a CopyOnWriteArrayList (#508)
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 <mi...@gmail.com>
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 <mg...@palantir.com>
---
.../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>();
}
}
}