2011-04-27 28 views
1

目前我开始一些线程,如调度程序和socketserver,如米纳通过ServletContextListerner。但是在这个tomcat之后无法正确关机。我该怎么做才能释放套接字或杀死线程。如何彻底阻止tomcat而我有套接字和线程

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(); 
     } 

} 

回答

0

首先使用thread.setDaemon(true)告诉JVM使线程成为守护进程线程。那么它会不是阻止Tomcat关机。