[ 
https://issues.apache.org/jira/browse/LOG4J2-626?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13986258#comment-13986258
 ] 

Remko Popma commented on LOG4J2-626:
------------------------------------

It should not matter whether you use asynchronous or synchronous logging. When 
the application logs a message, Log4j will take a snapshot of the ThreadContext 
map of that thread. The snapshot will not change even if the application later 
modifies the ThreadContext map.

Depending on your configuration, you may see some or all of the ThreadContext 
values in the resulting log file. What you see in the log are the values of the 
ThreadContext at the time that the application called {{logger.log(message)}} 
and Log4j took a ThreadContext map snapshot.

Does this match what you are seeing?

One thing to be aware of: if you are using a thread pool (and most web 
application servers do), you are re-using threads. So it may be a good idea to 
"clean" the ThreadContext from the thread after you are done with it.

> ThreadContext for Asynchronous logger in multithreaded environmant is 
> overwriting the values.
> ---------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-626
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-626
>             Project: Log4j 2
>          Issue Type: Question
>          Components: API
>    Affects Versions: 2.0-rc1
>         Environment: java 7
>            Reporter: sivan
>
> ThreadContext for Asynchronous loggers in multithreaded environmant is 
> overwriting the values. Is there is any way to use the custom key value pairs 
> in such an environment?
> The log4j2 document says that the values in threadcontext may overwrite by 
> asynchronous logging in multithreaded envirnment. We are implemented the 
> log4j2 asynchronous logging in our single sign on (SSO) framework and the 
> threadcontext is used to store some parameter values like sessionId, firm, 
> user etc and these values needs to be included in the log entry. At a time 
> many users will log into our site by using SSO. Is the threadcontext values 
> will change by asynchronous logging in multithreaded envirnment? If so, is 
> there any other way to store these values in thread safe manner?
> Log4j2 will not modify this. that is OK. But when many users at a time uses 
> single sign on then what will happen to the key value pairs in the 
> threadcontext. Is they will modify in multithreaded environment by 
> asynchronous logger?



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to