You ask two questions:
Question 1: calls the System.exit () method inside the Servlet destroy () method to force the destruction of any non-daemon threads?
A call to System.exit () inside ANY method associated with a servlet is always 100% incorrect. Your code is not the only code running in the JVM - even if you are the only servlet executing (the servlet container has resources that it will need to clear when the JVM really exits.)
- destroy(). , , . ( MyThread ServletManagedThread):
public class MyServlet extends HttpServlet {
private List<ServletManagedThread> threads = new ArrayList<ServletManagedThread>();
public void init() {
ServletManagedThread t = new MyThread();
threads.add(t);
t.start();
}
public void destroy() {
for(ServletManagedThread thread : threads) {
thread.stopExecuting();
}
}
}
public abstract class ServletManagedThread extends Thread {
private boolean keepGoing = true;
protected abstract void doSomeStuff();
protected abstract void probablySleepForABit();
protected abstract void cleanup();
public void stopExecuting() {
keepRunning = false;
}
public void run() {
while(keepGoing) {
doSomeStuff();
probablySleepForABit();
}
this.cleanup();
}
}
, / concurrency, , , , , , , .
2: Tomcat 5.0.30 ( , Tomcat 6.xx) , System.exit() destroy() ?
. Microsoft , 1053 , Windows , . , Tomcat -, . , System.exit() . Tomcat ( , Catalina) VM (see org.apache.catalina.startup.Catalina.start(), , 5.0.30). JVM System.exit(). , .
(triggered by your System.exit()) ( - ), , 1053, Runtime.exit(int) ( System.exit()):
, . , ; .
" ", , 1053.
, , .
, ( ), .
, System.exit() Tomcat - .