Repository: logging-log4j2
Updated Branches:
  refs/heads/master 215d934af -> 16e7ef70c


LOG4J2-1010 fix performance issue where new context map object created for each 
call when empty


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

Branch: refs/heads/master
Commit: 4e4d133cac306a6f0c0b6b9923ecba9de18a2450
Parents: c8ee4b3
Author: rpopma <rpo...@apache.org>
Authored: Thu Sep 22 10:51:18 2016 +0900
Committer: rpopma <rpo...@apache.org>
Committed: Thu Sep 22 10:51:18 2016 +0900

----------------------------------------------------------------------
 .../CopyOnWriteSortedArrayThreadContextMap.java    | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e4d133c/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
----------------------------------------------------------------------
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
index a8ced14..71afbef 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
@@ -36,6 +36,12 @@ class CopyOnWriteSortedArrayThreadContextMap implements 
ThreadContextMap, Thread
         MutableContextDataSupplier {
 
     /**
+     * Property name ({@value} ) for selecting {@code InheritableThreadLocal} 
(value "true") or plain
+     * {@code ThreadLocal} (value is not "true") in the implementation.
+     */
+    public static final String INHERITABLE_MAP = 
"isThreadContextMapInheritable";
+
+    /**
      * The default initial capacity.
      */
     protected static final int DEFAULT_INITIAL_CAPACITY = 16;
@@ -45,11 +51,10 @@ class CopyOnWriteSortedArrayThreadContextMap implements 
ThreadContextMap, Thread
      */
     protected static final String PROPERTY_NAME_INITIAL_CAPACITY = 
"log4j2.ThreadContext.initial.capacity";
 
-    /**
-     * Property name ({@value} ) for selecting {@code InheritableThreadLocal} 
(value "true") or plain
-     * {@code ThreadLocal} (value is not "true") in the implementation.
-     */
-    public static final String INHERITABLE_MAP = 
"isThreadContextMapInheritable";
+    private static final MutableContextData EMPTY_CONTEXT_DATA = new 
ArrayContextData();
+    static {
+        EMPTY_CONTEXT_DATA.freeze();
+    }
 
     private final ThreadLocal<MutableContextData> localMap;
 
@@ -162,7 +167,7 @@ class CopyOnWriteSortedArrayThreadContextMap implements 
ThreadContextMap, Thread
     @Override
     public MutableContextData getMutableContextData() {
         final MutableContextData map = localMap.get();
-        return map == null ? createMutableContextData() : map;
+        return map == null ? EMPTY_CONTEXT_DATA : map;
     }
 
     @Override

Reply via email to