Calling System.exit() in Servlet's destroy() method

后端 未结 4 546
迷失自我
迷失自我 2020-12-15 14:01

This is a follow up to my earlier question.

Tomcat 5.0.28 had a bug where the Servlet\'s destroy() method was not being invoked by the container on a shutdown. This

4条回答
  •  一整个雨季
    2020-12-15 14:49

    Calling System.exit() inside a Servlet's destroy() method to forcefully kill any non-daemon threads is a good idea?

    Not a good idea. You will forcefully kill all threads, which might include part of Tomcat that is currently shutting down the system. This will cause Tomcat to un-gracefully shutdown. This can also prevent shutdown handlers from running which can lead to all sorts of problems.

    Why does Tomcat 5.0.30 and (later versions including Tomcat 6.x.x) fail to shutdown properly if there's a System.exit() in the destroy() method of the Servlet.

    A lot of code executes after a Servlet destory. The Context destroy and all of its other listeners for one... other servlets. Other applications. Tomcat itelf. By calling System.exit, you prevent all of that from running.

    A better question is what are thse non-daemon threads, why are they running, and who starts them?

提交回复
热议问题