首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tomcat 6内存泄漏日志条目

Tomcat 6内存泄漏日志条目
EN

Stack Overflow用户
提问于 2011-02-04 22:37:54
回答 3查看 22.8K关注 0票数 8

下面是我在CentOS机器上的Catalina.out文件中唯一条目的输出。我正在运行Tomcat6和Spring3以及我的应用程序。它们有一大堆,所以我只是挑选了一些不断重复的。这种情况并不总是发生,但至少每周发生一次。

问题是我能做些什么来防止这种情况的发生?

代码语言:javascript
复制
Feb 3, 2011 2:37:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

SEVERE: The web application [] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

Feb 3, 2011 2:37:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

SEVERE: The web application [] appears to have started a thread named [com.iteezy.shared.domain.DirEntry.data] but has failed to stop it. This is very likely to create a memory leak.


Feb 3, 2011 2:37:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named

[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.


Feb 3, 2011 2:37:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads  

SEVERE: The web application [] appears to have started a thread named [File Reaper] but has failed to stop it. This is very likely to create a memory leak.

Feb 3, 2011 2:37:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

SEVERE: The web application [] appears to have started a thread named [pool-1-thread-22] but has failed to stop it. This is very likely to create a memory leak.  

37:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
b application [] appears to have started a thread named 

[org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2] but has failed to stop it. This is very likely to create a memory leak.

37:48 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap

b application [] created a ThreadLocal with key of type [net.sf.json.AbstractJSON$1] (value [net.sf.json.AbstractJSON$1@40bbb3d6]) and a value of type [java.util.HashSet] (value [[]]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-10-27 15:57:26

当您定义一个外部标志时,线程应轮询该标志并在设置为volatile.时退出,它必须为否则,线程可能永远看不到其他线程所做的更改。

然而,在标准应用编程接口中已经有一个类似的特性-它被称为interrupt()方法和Thread.currentThread().isInterrupted()。不需要复制已经存在的逻辑。请参阅:Stopping a specific java thread

也就是说,在每个线程上调用interrupt()也不是一个好主意,因为不能保证所有线程都响应它。检查您的异常时,我注意到以下线程未被正确清理:

  • com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0 -关闭C3P0数据源。由于您使用的是Spring,因此只需添加destroy-method="close"。我们已经完成了这个thread.
  • File Reaper --据我所知,这个线程是由FileCleaningTracker创建的。您需要在关闭应用程序时显式调用FileCleaningTracker.exitWhenFinished() (或者当不再需要该类时,我从未使用过它),或者让Spring来执行此操作(参见上文)。一些第三方库可能会使用它,但没有正确关闭-这意味着它有一个bug.
  • pool-1-thread-22 -这是由ExecutorService中的Executors实用程序创建的线程之一。确保在shutdown.
  • org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2 - Quartz工作线程(实际运行作业的线程)期间对应用程序中的每个这样的池调用shutdown()SchedulerFactoryBean会自动为您关闭调度程序,我认为Tomcat在这一点上是错误的,我也经常看到这个错误。尽管如此,将SchedulerFactoryBean.waitForJobsToCompleteOnShutdown设置为true似乎可以解决this.
  • com.iteezy.shared.domain.DirEntry.data问题--我不确定这个问题。要么是您自己的线程需要在关机时中断,要么是H2数据库线程(?)需要检查它的堆栈以猜测它是从哪里来的。

底线是:不要只是杀死所有移动的东西(实际上,Tomcat在发出这个警告后会为你做这件事),而是要确定线程来自哪里,并使用框架/库特定的close()方法来进行进一步的清理。请温柔些。

票数 12
EN

Stack Overflow用户

发布于 2011-02-04 22:56:30

在它的destroy()方法中设置一个Servlet来管理它。线程可以检查一个标志,看看它们是否必须继续。

在servlet中,在destroy方法中执行以下操作。显然,您需要能够访问Collection<MyThread>,但如何获得访问权限实际上取决于系统的设置方式。

代码语言:javascript
复制
destroy() {
    for (MyThread thread : myThreads) {
        thread.stopProcessing();
    }
}

您的MyThread类将具有类似以下内容:

代码语言:javascript
复制
public class MyThread {
    private boolean finished = false;

    @Override
    public void run() {
        while (!finished) {
            //do something
        }
    }

    public void stopProcessing() {
        finished = true;
    }
}
票数 1
EN

Stack Overflow用户

发布于 2011-02-04 22:45:18

正确关闭您的webapp应用程序。不要让这些线程继续运行。

或者,不要一直重新部署webapp。

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

https://stackoverflow.com/questions/4899205

复制
相关文章

相似问题

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