当我试图在Java8上停止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时,它不会关闭它,我必须手动终止进程。
怎么啦?
发布于 2015-01-23 17:34:07
没什么好担心的。这是tomcat在检测到应用程序启动了自己的Thread或创建了ThreadLocal时输出的标准消息。如果您在关闭时终止线程,并在不再需要线程局部变量时将其删除,则不会有任何问题。
为什么我会得到所有这些内存泄漏错误?同样,当我运行shutdown时,它不会关闭它,我必须手动终止进程。
我见过这种行为,当一个应用程序启动了ScheduledExecutor (但这会发生在任何其他Thread/TheadPool上),而不是在contextDestroyed上关闭它。因此,请检查您是否在应用程序/服务器停止时关闭线程。
现在谈谈服务器为什么不停止的具体问题: JDBC驱动程序在中注册为单例,并与所有why应用程序共享。更多信息here.问题的最佳解决方案是移动Tomcat的/lib文件夹中的MySQL驱动程序。如果你不能做到这一点,你可以尝试this,但它更像是一个黑客而不是一个真正的解决方案。
发布于 2015-01-23 17:10:41
我认为你的问题和this类似。当你重新部署应用程序时,apache会在system.gc();不工作的地方逐步部署它,在开发阶段重新部署几次之后,永久生成的空间会变满,你会得到内存泄漏错误。
请在几次重新部署后继续重新启动您的服务器,以便通过重新启动可以清除PermGen空间。
或
您也可以通过更改服务器中的PermGen空间来解决此问题。请访问here。
我希望这能对你有所帮助。
https://stackoverflow.com/questions/28105803
复制相似问题