首页 / JAVA / java – Tomcat8内存泄漏
java – Tomcat8内存泄漏
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Tomcat8内存泄漏,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3319字,纯文字阅读大概需要5分钟。
内容图文
![java – Tomcat8内存泄漏](/upload/InfoBanner/zyjiaocheng/951/ad693591ec304aeb8cc70bd3b458486f.jpg)
当我尝试在Java 8上停止tomcat8时,我收到一些内存泄漏错误:
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
23-Jan-2015 08:18:10.202 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [pool-5-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread
23-Jan-2015 08:18:10.205 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [com.util.ThreadLocalProperties$1] (value [com.util.ThreadLocalProperties$1@2fafda6e]) and a value of type [java.util.Properties] (value [{}]) 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.
ThreadLocalProperties类是:
public class ThreadLocalProperties extends Properties {
private static final long serialVersionUID = -4260632266508618756L;
private final ThreadLocal<Properties> localProperties = new ThreadLocal<Properties>() {
@Override
protected Properties initialValue() {
return new Properties();
}
};
public ThreadLocalProperties(Properties properties) {
super(properties);
}
@Override
public String getProperty(String key) {
String localValue = localProperties.get().getProperty(key);
return localValue == null ? super.getProperty(key) : localValue;
}
@Override
public Object setProperty(String key, String value) {
return localProperties.get().setProperty(key, value);
}
public ThreadLocal<Properties> getThreadLocal() {
return localProperties;
}
}
我这样开始和停止它:
@WebListener()
public class GeneralListener implements ServletContextListener {
ThreadLocalProperties threadLocalProperties = new ThreadLocalProperties(System.getProperties());
@Override
public void contextDestroyed(ServletContextEvent arg0) {
threadLocalProperties.getThreadLocal().remove();
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.setProperties(threadLocalProperties);
}
}
为什么我会得到所有这些内存泄漏错误?同样,当我运行shutdown时,它不会关闭它,我必须手动终止进程.
怎么了?
解决方法:
没有什么可担心的.这是一个标准消息tomcat输出,当它检测到应用程序已启动它自己的Thread或创建一个ThreadLocal.如果在关闭时终止线程并在不再需要时删除threadlocals,那么就没有问题了.
Why would I get all this memory leaks errors? as well, when I run
shutdown, it doesn’t shut it down, I have to manually kill the
process.
我已经看到这种行为,当一个应用程序启动了ScheduledExecutor(但这将发生在任何其他Thread / TheadPool)并且没有在contextDestroyed上关闭它.因此,请检查您是否在应用程序/服务器停止时关闭了线程.
现在你的具体问题为什么服务器不会停止:
JDBC驱动程序在JVM中作为单例注册,并与所有Web应用程序共享.更多信息here.解决问题的最佳方法是在Tomcat的/ lib文件夹中移动MySQL驱动程序.如果你不能这样做,你可以尝试this,但它更像是一个黑客而不是一个真正的解决方案.
内容总结
以上是互联网集市为您收集整理的java – Tomcat8内存泄漏全部内容,希望文章能够帮你解决java – Tomcat8内存泄漏所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。