繁体   English   中英

使用tomcat可能发生内存泄漏

[英]Possible memory leak using tomcat

我开发了一个广泛使用线程的Webbapp。 我们需要以固定的时间间隔监控一些资源然后采取行动。

为此,我们开发了一个包装一个 ScheduledThreadPoolExecutorThreadManager 我们允许执行者的任何方法,我们只使用这个管理器来确保每个人都使用相同的线程池实例(管理器是一个Singleton ...)

然后,当我们关闭上下文时,我们有一个ServletContextListener来负责正确关闭执行程序:

 ejecutor.shutdown();
 try
 {
      ejecutor.awaitTermination(10, TimeUnit.SECONDS);
 }
 catch (InterruptedException ie)
 {
     Thread.currentThread().interrupt();
 }
 System.out.println("Llamo al shutdownnow");
 ejecutor.shutdownNow();
 ejecutor = null;

但是,当我们关闭tomcat /卸载上下文时,我们会遇到很多错误:

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

如果我们通过询问活动线程的数量来监视执行程序,在关闭之后,它会继续说没有更多活动线程,但我们继续在tomcat上找到相同的错误。

有任何想法吗?

更新:提供的更多信息挂起的线程是Executor中安排的线程。 所有这些都覆盖了interrupt()所以它像:

System.out.println("Me intentan interrumpir!!");
run = false;
super.interrupt();

然后,在contextDestroyed期间,我执行已经提到的关闭...但是从中断出来的系统甚至没有被打印出来!

执行程序将ExecuteExistingDelayedTasksAfterShutdownPolicy设置为false ...

仍然保持线程活着......

最后,我发现了一些东西:

每次我使用ScheduledThreadPoolExecutor tomcat都无法关闭undeploy / close / restart上的池线程,从而导致可能的内存泄漏(应该没问题,因为tomcat无法关闭它们,但是在它们杀死之后,所以没问题,但客户不会允许它......),而其他服务器就像魅力......

实际上,我创建了一个核心大小为25的ScheduledThreadPoolExecutor,然后关闭它(没有运行或调度),并且tomcat仍然无法清理池化线程。

所以我的解决方案是使用Timer,而我等待补丁...(它发生在tomcat 6.0和jdk 1.5.0_22)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM