在我的webapp中,我创建了一个使用固定大小的ThreadPool的ExecutorService
的服务。我在整个应用程序生命周期中重复使用相同的ExecutorService
。在webapp中优雅地关闭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的。索姆斯SO线程已经谈论这个,但我找不到一个干净的方式来处理这个问题。
我应该使用ShutdownHook
建议@ Tim-bender在Graceful shutdown of threads and executor?还是应该使用CachedThreadPool来代替?
正是我需要知道的 –