Hi Remko/Matt,

Yes the AsyncLogger.ThreadNameStrategy=UNCACHED solved it. 

Thank you

On 2017-02-15 23:21 (-0500), Remko Popma <remko.po...@gmail.com> wrote: 
> Hi Leon,
> 
> Yes by default the thread name is cached. 
> There is a system property to switch that off: see 
> https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/async/ThreadNameCachingStrategy.java
> 
> The reason for the caching is that every call to get the current thread's 
> name creates a new String object, which I found impacted performance 
> measurably. 
> 
> Why Thread is implemented to store its name in a char[] array and create a 
> new String on each query I don't know. May have to do with interaction with 
> native code.
> 
> Remko
> 
> Sent from my iPhone
> 
> > On Feb 16, 2017, at 4:37, Leon Finker <leon...@gmail.com> wrote:
> > 
> > Hi,
> > 
> > Is there any thread name caching going on with log4j2 (doesn't matter 
> > sync/async)? If I have a thread pool of tasks and call 
> > Thread.currentThread().setName (with unique id) in the beginning of the 
> > task execution, I sometimes see reuse of previous thread name in the log 
> > statements. Id is UUID, so it's definitely unique. And if I do System.out 
> > on the current thread name after setting it, I do see the new name as 
> > expected. But in log statements the thread name is from the previous set. 
> > The pattern layout is: [%date{DEFAULT}{UTC}Z][%level][%thread:%tid][%c{3}] 
> > %message%n
> > 
> > log4j:2.7
> > 
> > Any ideas what could be causing the thread name reuse?
> > 
> > Thank you
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
> > For additional commands, e-mail: log4j-dev-h...@logging.apache.org
> > 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to