Should threads have special design to be shutdown gracefully by Tomcat?

前端 未结 3 2237
滥情空心
滥情空心 2021-02-19 11:57

I have developed a multithreaded web application that runs in Tomcat. But I cannot use

shutdown.bat

Tomcat didn\'t stop gracefully. In the deb

3条回答
  •  攒了一身酷
    2021-02-19 12:41

    You need to cancel your threads, preferably by calling interrupt on them and making sure they are written in such a way that they respond to the interruption -- meaning, checking their interrupted flag and responding intelligently to InterruptedExceptions (not just eating them and continuing on).

    The above advice assumes you don't want your threads to drop what they're doing immediately. If you are ok with that then make them daemons.

提交回复
热议问题