Stephan van Hulst wrote:Why not use System.exit(0) ?
System.exit() would potentially kill the entire Servlet Engine/server - bringing down multiple applications. Not something you want to do (and often blocked by a Servlet Engine's security manager).
Threads are not really related to each other, once you start them you can not expect there to be a relationship between the new Threads and the Threads that created them. There are a couple of work-arounds:
1) Use a ThreadGroup. Put all of the new Threads you want to cancel with the main one into a single ThreadGroup, then call ThreadGroup#interrupt() or iterate over the Threads in the group and interrupt them individually.
2) Collect all of the related Threads into some collection that is accessible to the 'main' thread when it gets interrupted. Then iterate over those Threads and interrupt them.
3) If you just want a safe way to stop a single web application in a server, you Server provider may have an admin console built in, you might try using that.
For the first two options you might have your Servlet Engine's security policy to contend with.