Spring ThreadPoolTask​​Executor导致Tomcat中的MemoryLeak

时间:2012-11-28 13:42:31

标签: java spring tomcat concurrency

我有一个在Tomcat 7中运行的Spring 3应用程序。

我使用Spring的ThreadPoolTask​​Executor来处理队列中的一些消息。我有一个使用@Scheduled的bean,它每100毫秒向执行程序提交一次任务。

但是,我注意到当我关闭Tomcat时,它警告我它无法关闭某些任务。

SEVERE: The web application appears to have started a thread named [taskExecutor-9] but has failed to stop it. This is very likely to create a memory leak.
Nov 28, 2012 1:29:18 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

有谁知道如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

在连接setWaitForTasksToCompleteOnShutdown(true)时尝试拨打ThreadPoolTaskExecutor

文档在这里:http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.html#setWaitForTasksToCompleteOnShutdown(boolean),它表示默认值为false。

答案 1 :(得分:0)

您是否在executor bean上注册了shutdown方法?通过这样做,我能够解决这个问题:

@Bean(destroyMethod="shutdown")
     public Executor taskExecutor() {
         return Executors.newScheduledThreadPool(100);
     }

参考:

  

http://docs.spring.io/spring/docs/3.2.0.RC1_to_3.2.0.RC2/changes/docdiffs_org.springframework.scheduling.annotation.html