gpt4 book ai didi

java - Spring ThreadPoolTask​​Executor 导致 Tomcat 内存泄漏

转载 作者:行者123 更新时间:2023-11-28 21:50:22 25 4
gpt4 key购买 nike

我有一个在 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

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

最佳答案

您是否在执行程序 bean 上注册了关闭方法?我能够通过这样做来解决这个问题:

@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

关于java - Spring ThreadPoolTask​​Executor 导致 Tomcat 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13606453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com