Home > Blockchain >  Log4j2 tomcat 10 memory leaks on shutdown
Log4j2 tomcat 10 memory leaks on shutdown

Time:03-28

I have memory leaks at my tomcat 10.0.16 servlet application. I am using Log4j2 2.17.2 version, and after tomcat shutdown I see next logs:

02-Mar-2022 22:14:54.513 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [MVCProject_war_exploded] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@43f82e78]) and a value of type [org.apache.logging.log4j.core.pattern.DatePatternConverter.FixedFormatter] (value [org.apache.logging.log4j.core.pattern.DatePatternConverter$FixedFormatter@6986bbaf]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
02-Mar-2022 22:14:54.529 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [MVCProject_war_exploded] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4879dfad]) and a value of type [org.apache.logging.log4j.message.ReusableSimpleMessage] (value [org.apache.logging.log4j.message.ReusableSimpleMessage@4758820d]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
02-Mar-2022 22:14:54.529 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [MVCProject_war_exploded] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@74eb909f]) and a value of type [org.apache.logging.log4j.core.impl.MutableLogEvent] (value [org.apache.logging.log4j.core.impl.MutableLogEvent@28ec166e]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

My pom.xml for Log4j2 is:

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jakarta-web</artifactId>
            <version>2.17.2</version>
        </dependency>

And also log4j2 config

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

Most common fix is to add log4j-jakarta-web, but this does not works for me

CodePudding user response:

Fully deleting target folder and recompiling my project seems like resolved my issue.

  • Related