Alex Rivera | Logout

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

Asked 2011-12-30T14:28:23.590
13

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

shutdown.bat

Tomcat didn't stop gracefully. In the debugger I saw that threads continue to run after shutdown command. Do I have to fix my application code to meet special requirements ? Thanks.

Edit
Report

1 Answer

5

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.

answered 2011-12-30T14:33:27.617

Your Answer