Log4j2 tomcat 10 关闭时内存泄漏

发布于 2025-01-11 16:27:11 字数 3157 浏览 0 评论 0原文

我的 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,但这对我不起作用

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2025-01-18 16:27:11

完全删除目标文件夹并重新编译我的项目似乎解决了我的问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文