Repository: logging-log4j2
Updated Branches:
  refs/heads/master ae87a679f -> d2db53d17


LOG4J2-1583 avoid instantiating ThreadLocal StringBuilder until required


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d2db53d1
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d2db53d1
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d2db53d1

Branch: refs/heads/master
Commit: d2db53d178a9c6d73bd8a8efd0017f5a2bbed16c
Parents: ae87a67
Author: rpopma <rpo...@apache.org>
Authored: Sat Sep 17 22:11:00 2016 +0900
Committer: rpopma <rpo...@apache.org>
Committed: Sat Sep 17 22:11:00 2016 +0900

----------------------------------------------------------------------
 .../logging/log4j/message/ReusableParameterizedMessage.java     | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d2db53d1/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
----------------------------------------------------------------------
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
 
b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
index 85573b1..de9918c 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
@@ -33,7 +33,7 @@ public class ReusableParameterizedMessage implements 
ReusableMessage {
     private static final int MIN_BUILDER_SIZE = 512;
     private static final int MAX_PARMS = 10;
     private static final long serialVersionUID = 7800075879295123856L;
-    private ThreadLocal<StringBuilder> buffer = new ThreadLocal<>(); // 
non-static: LOG4J2-1583
+    private ThreadLocal<StringBuilder> buffer; // non-static: LOG4J2-1583
 
     private String messagePattern;
     private int argCount;
@@ -290,6 +290,9 @@ public class ReusableParameterizedMessage implements 
ReusableMessage {
     }
 
     private StringBuilder getBuffer() {
+        if (buffer == null) {
+            buffer = new ThreadLocal<>();
+        }
         StringBuilder result = buffer.get();
         if (result == null) {
             final int currentPatternLength = messagePattern == null ? 0 : 
messagePattern.length();

Reply via email to