This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 9788f33 LOG4J2-2990 - Reduce garbage by using putAll when copying the
ThreadContext for SLF4J
9788f33 is described below
commit 9788f33fc62b3b4012489a603772433d3440e6b0
Author: Ralph Goers <[email protected]>
AuthorDate: Sun Feb 7 14:58:24 2021 -0700
LOG4J2-2990 - Reduce garbage by using putAll when copying the ThreadContext
for SLF4J
---
.../src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java | 4 +---
.../src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java | 4 +---
src/changes/changes.xml | 3 +++
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git
a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
index ba32dc6..b12c297 100644
---
a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
+++
b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
@@ -55,8 +55,6 @@ public class Log4jMDCAdapter implements MDCAdapter {
@SuppressWarnings("unchecked") // nothing we can do about this, restricted
by SLF4J API
public void setContextMap(@SuppressWarnings("rawtypes") final Map map) {
ThreadContext.clearMap();
- for (final Map.Entry<String, String> entry : ((Map<String, String>)
map).entrySet()) {
- ThreadContext.put(entry.getKey(), entry.getValue());
- }
+ ThreadContext.putAll(map);
}
}
diff --git
a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
index ba32dc6..b12c297 100644
---
a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
+++
b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
@@ -55,8 +55,6 @@ public class Log4jMDCAdapter implements MDCAdapter {
@SuppressWarnings("unchecked") // nothing we can do about this, restricted
by SLF4J API
public void setContextMap(@SuppressWarnings("rawtypes") final Map map) {
ThreadContext.clearMap();
- for (final Map.Entry<String, String> entry : ((Map<String, String>)
map).entrySet()) {
- ThreadContext.put(entry.getKey(), entry.getValue());
- }
+ ThreadContext.putAll(map);
}
}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 35183f7..bd2e261 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
-->
<release version="2.14.1" date="2021-MM-DD" description="GA Release
2.14.1">
<!-- FIXES -->
+ <action issue="LOG4J2-2990" dev="rgoers" type="fix" due-to="Diogo
Monteiro">
+ Reduce garbage by using putAll when copying the ThreadContext for
SLF4J.
+ </action>
<action issue="LOG4J2-3006" dev="rgoers" type="fix">
Directly create a thread instead of using the common ForkJoin pool
when initializing ThreadContextDataInjector"
</action>