开发者

How to stop tomcat thoroughly while i have socket and thread in it

开发者 https://www.devze.com 2023-03-01 02:45 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消