How to stop an executor thread when Tomcat is stopped?

旧巷老猫 提交于 2019-11-28 10:23:21

It's a real problem. Non-daemon threads pooled by your executor don't go away by themselves, if you don't call shutdown on the executor then the threads will stay alive and prevent the JVM from exiting.

Make a ServletContextListener that calls shutdown on your executor on contextDestroyed.

Alternatively you could make the threads returned by your ThreadFactory daemon threads, so that they would exit when the last non-daemon thread terminates. Since you're doing data retrieval it would seem better to avoid this since it could leave database resources unclosed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!