Currently i start some threads such scheduler and socketserver such as mina via to ServletContextListerner. But after this tomcat can not be shutdown correctly. What should i do release the socket or kill the thread .
public class ServerListener implements ServletContextListener{
开发者_高级运维 public void contextDestroyed(ServletContextEvent arg0){
//what should i do here
}
public void contextInitialized(ServletContextEvent arg0){
new Thread(new Runnable(){
public void run(){
SocketMain.main(null);
}
}).start();
new Thread(new Runnable(){
public void run(){
SccheduleMain.main(null);
}
}).start();
}
}
First of all use thread.setDaemon(true)
to tell the JVM to make the thread a daemon thread. Then it will NOT prevent Tomcat to shutdown.
精彩评论