ppkarwasz commented on code in PR #2517:
URL: https://github.com/apache/logging-log4j2/pull/2517#discussion_r1579370783


##########
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java:
##########
@@ -326,12 +326,10 @@ public String getThreadContextMap() {
             return threadContextMapClass;
         }
         // Default based on properties
-        if (Constants.ENABLE_THREADLOCALS) {
-            return props.getBooleanProperty(GC_FREE_THREAD_CONTEXT_PROPERTY)
-                    ? GC_FREE_THREAD_CONTEXT_PROPERTY
-                    : COPY_ON_WRITE_CONTEXT_MAP;
+        if (props.getBooleanProperty(GC_FREE_THREAD_CONTEXT_PROPERTY, 
!Constants.IS_WEB_APP)) {
+            return GC_FREE_THREAD_CONTEXT_PROPERTY;
         }
-        return WEB_APP_CONTEXT_MAP;
+        return Constants.IS_WEB_APP ? WEB_APP_CONTEXT_MAP : 
COPY_ON_WRITE_CONTEXT_MAP;

Review Comment:
   This change probably merits a longer discussion.
   
   If the user does not provide a value for `enableThreadlocals`, the type of 
thread context map is determined by `isWebapp` and 
`garbagefreeThreadContextMap` in the following way:
   
   ## Before
   
   |          |       | garbagefreeThreadContextMap |             |             
|
   
|----------|-------|-----------------------------|-------------|-------------|
   |          |       | `false`                       | `true`        | `null`  
      |
   | **isWebapp** | `false` | CopyOnWrite                 | GargageFree | 
**CopyOnWrite** |
   |          | `true`  | WebApp                      | **WebApp**      | 
WebApp      |
   
   
   ## After
   
   |          |       | garbagefreeThreadContextMap |             |             
|
   
|----------|-------|-----------------------------|-------------|-------------|
   |          |       | `false`                       | `true`        | `null`  
      |
   | **isWebapp** | `false` | CopyOnWrite                 | GarbageFree | 
**GarbageFree** |
   |          | `true`  | WebApp                      | **GarbageFree**      | 
WebApp      |
   
   This means that we not only have a change for web-app users (as expected), 
but also for non web-app users: a non web-app user will have `GarbageFree` as 
context map implementation, unless he **explicitly** disables it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to