Shutdown ExecutorService gracefully in webapp?

后端 未结 2 1358
梦如初夏
梦如初夏 2020-12-03 05:15

In my webapp, I created a service that is using an ExecutorService with fixed size ThreadPool. I reuse the same ExecutorService during the whole ap

2条回答
  •  长情又很酷
    2020-12-03 05:25

    In addition to what Tomasz suggested you can also use CachedThreadPool

    Threads that have not been used for sixty seconds are terminated and removed from the cache. Thus, a pool that remains idle for long enough will not consume any resources

    So a very good solution would be use CachedThreadPool and shutdown it in ServletContextListener.contextDestroyed().

提交回复
热议问题