首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Log4j 2内存泄漏

Log4j 2内存泄漏
EN

Stack Overflow用户
提问于 2021-11-14 06:43:28
回答 1查看 487关注 0票数 0

我使用Tomcat10.0.6,log4j 2.14.1。当我关闭Tomcat时,我会看到以下日志:

代码语言:javascript
复制
13-Nov-2021 22:32:32.915 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@59402b8f]) and a value of type [org.apache.logging.log4j.core.impl.MutableLogEvent] (value [org.apache.logging.log4j.core.impl.MutableLogEvent@7188af83]) 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.
13-Nov-2021 22:32:32.915 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@6be968ce]) and a value of type [org.apache.logging.log4j.core.pattern.DatePatternConverter.PatternFormatter] (value [org.apache.logging.log4j.core.pattern.DatePatternConverter$PatternFormatter@7c37508a]) 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.
13-Nov-2021 22:32:32.917 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@247310d0]) and a value of type [org.apache.logging.log4j.message.ReusableSimpleMessage] (value [org.apache.logging.log4j.message.ReusableSimpleMessage@1033576a]) 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.
13-Nov-2021 22:32:32.917 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@303cf2ba]) and a value of type [org.apache.logging.log4j.core.pattern.DatePatternConverter.PatternFormatter] (value [org.apache.logging.log4j.core.pattern.DatePatternConverter$PatternFormatter@76494737]) 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.
13-Nov-2021 22:32:32.921 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@59402b8f]) and a value of type [org.apache.logging.log4j.core.impl.MutableLogEvent] (value [org.apache.logging.log4j.core.impl.MutableLogEvent@17fc391b]) 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.
13-Nov-2021 22:32:32.921 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@6be968ce]) and a value of type [org.apache.logging.log4j.core.pattern.DatePatternConverter.PatternFormatter] (value [org.apache.logging.log4j.core.pattern.DatePatternConverter$PatternFormatter@2b30a42c]) 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.
13-Nov-2021 22:32:32.926 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@247310d0]) and a value of type [org.apache.logging.log4j.message.ReusableSimpleMessage] (value [org.apache.logging.log4j.message.ReusableSimpleMessage@609e8838]) 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.xml

代码语言:javascript
复制
<Configuration>
    <Properties>
        <Property name="property_console">%d{HH:mm:ss} %-5level %logger{1} - %msg%n</Property>
        <Property name="property_file">
            %d{yyyy-MM-dd HH:mm:ss} %-5level [%t] %logger{6} - %msg%n
        </Property>
    </Properties>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="${property_console}"/>
        </Console>
        <RollingFile name="FileRolling" fileName="logs/log.txt" append="true" filePattern="logs/${date:yyyy-MM-dd}/%d{yyyy-MM-dd_HH-mm}.txt">
            <PatternLayout pattern="${property_file}"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="100 K"/>
            </Policies>
            <DefaultRolloverStrategy max="10"/>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="ALL">
            <AppenderRef ref="FileRolling"/>
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

我的log4j2 in pom.xml

代码语言:javascript
复制
<dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
        <version>2.14.1</version>
</dependency>

我认为这可能与我使用jakarta.servlet 3.0依赖项有关,但我不知道。将.jar移动到tomcat/lib不会得到任何更改。有什么不对的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-16 17:59:00

您的假设是正确的:log4j-web需要支持Servlet3.0中引入的S

自Servlet5.0( Tomcat 10实现)以来,由于之间的版权纠纷,类的全名从javax.servlet.ServletContainerInitializer更改为jakarta.servlet.ServletContainerInitializer。因此,log4j-web的所有版本都不能在Tomcat 10上工作。

编辑:由于Log4j 2.15.0版本的支持雅加达EE 9+服务器的log4j-web是可用的:log4j-jakarta-web,它解决了特性请求LOG4J2-2978

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69960854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档