In my webapp, I created a service that is using an ExecutorService
with fixed size ThreadPool. I reuse the same ExecutorService
during the whole application lifetime.
private static ExecutorService pool = Executors.newFixedThreadPool(8);
All is running in Tomcat which gives me the following error while shuting down:
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.
I do realize I need to shutdown the ExecutorService before shuting tomcat down. Soms SO thread already speak about this but I could not find a clean way to handle this.
Should I use a ShutdownHook
as suggested @Tim-bender in Graceful shutdown of threads and executor ? Or should I use a CachedThreadPool instead?