logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: Need to clear ThreadContext for each HTTP request?
Date Tue, 17 Apr 2018 02:52:26 GMT
Very good question. Please be aware that Log4j will *not* clear the ThreadContext. Your concern
that ThreadContext values may become visible to other threads because of Tomcat’s thread
pool is a legitimate concern. 

It is a good idea to explicitly clear values when the application is done with them. The CloseableThreadContext
can be useful here. 


(Shameless plug) Every java main() method deserves http://picocli.info

> On Apr 17, 2018, at 11:01, Kevin Jung <mykevinjung@gmail.com> wrote:
> Hello,
> I am using Log4j 2 ThreadContext with Tomcat.  I wonder if I need to clear
> ThreadContext at the end (or start) of HTTP request in order to avoid the
> context data being carried over to next HTTP request processing.
> I was assuming that thread context is cleared when Tomcat thread is put
> back in the thread pool and when a Tomcat thread starts processing new HTTP
> request, it starts with an empty thread context, nothing carried over from
> the previous HTTP request.  But that's my assumption, I want to make sure I
> do not need to clear at the end, like using a servlet filter.  Or should I
> use CloseableThreadContext to avoid carrying over among HTTP requests?
> Thanks,
> Kevin

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message