【发布时间】:2012-09-30 16:53:59
【问题描述】:
在我的 web 应用程序中,我创建了一个使用具有固定大小线程池的 ExecutorService 的服务。我在整个应用程序生命周期内重复使用相同的ExecutorService。
private static ExecutorService pool = Executors.newFixedThreadPool(8);
所有都在 Tomcat 中运行,关闭时出现以下错误:
appears to have started a thread named [pool-1-thread-1] but has failed to stop it. This is very likely to create a memory leak.
我确实意识到在关闭 tomcat 之前我需要关闭 ExecutorService。 Soms SO线程已经谈到了这个,但我找不到一个干净的方法来处理这个。
我应该按照Graceful shutdown of threads and executor 中建议的@Tim-bender 使用ShutdownHook 吗?还是应该改用 CachedThreadPool?
【问题讨论】:
标签: java multithreading tomcat6 executorservice