Log4j2 tomcat 关闭时发生 10 次内存泄漏
Log4j2 tomcat 10 memory leaks on shutdown
我的 tomcat 10.0.16 servlet 应用程序存在内存泄漏。我使用的是 Log4j2 2.17.2 版本,在 tomcat 关闭后我看到下一条日志:
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.
我的 Log4j2 pom.xml 是:
<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>
还有 log4j2 配置
<?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>
最常见的修复是添加 log4j-jakarta-web,但这对我不起作用
完全删除目标文件夹并重新编译我的项目似乎解决了我的问题。
我的 tomcat 10.0.16 servlet 应用程序存在内存泄漏。我使用的是 Log4j2 2.17.2 版本,在 tomcat 关闭后我看到下一条日志:
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.
我的 Log4j2 pom.xml 是:
<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>
还有 log4j2 配置
<?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>
最常见的修复是添加 log4j-jakarta-web,但这对我不起作用
完全删除目标文件夹并重新编译我的项目似乎解决了我的问题。