java - Log4j 线程上的 Tomcat 内存泄漏问题

标签 java multithreading memory-leaks log4j

我在 log4j v1 中遇到内存泄漏问题。如何解决此内存泄漏问题。 这个方法是定期检查我的类中的log4j.properties文件更新。

PropertyConfigutaror.configureAndWatch(time_ms);

但是在关闭tomcat期间出现内存泄漏问题。日志如下:

06-Oct-2016 15:13:55.973 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [myapp] appears to have started a thread named [Thread-10] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

java.lang.Thread.sleep(Native Method) org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:103)

提前致谢

最佳答案

Is there a way to get log4j to automatically reload a configuration file if it changes?

Yes. Both the DOMConfigurator and the PropertyConfigurator support automatic reloading through the configureAndWatch method. See the API documentation for more details.

Because the configureAndWatch launches a separate wathdog thread, and because there is no way to stop this thread in log4j 1.2, the configureAndWatch method is unsafe for use in J2EE envrironments where applications are recycled. (1)

第二个陈述对于像 Tomcat 这样的不成熟的应用程序服务器也是正确的。

如果您想在运行时重新加载配置,我建议更新到 log4j 2。

还可以编写自己的属性文件读取器并以编程方式设置日志配置。欲了解更多信息,请参阅Change Log4j properties at runtime .

关于java - Log4j 线程上的 Tomcat 内存泄漏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39903081/

相关文章:

java - 为什么并发线程限制没有按预期工作?

c++ - 使用 itoa() 的最佳实践是什么

ios - 使用仪器 - 设备泄漏

emacs - Emacs Lisp 的 lexical-let 何时会泄漏内存?

java - LocalDateTime 格式化程序始终至少返回毫秒

java - 在 varnish 后面使用 reSTLet 时出错(反向代理)

java - 如何修复 java.util.concurrent.CompletionException : java. lang.StackOverflowError

java - 通过环绕立体声扬声器输出多声道音频

java - 访问被拒绝找到属性 "vendor.debug.egl.swapinterval"当我运行我的应用程序时,我在 android studio 中不断收到此错误

c# - 栈空异常