服务器相关

1. 服务器用shutdown.sh或者catalina.sh stop停服务器,但是用ps -ef | grep tomcat 查看显示进程还在。

原因: 有一些线程还没有结束。

解决办法:写个监事事件。

public class ServerContextManager implements ServletContextListener{

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        TimerUtils.shutdown();//因为我代码里用到了ScheduledExecutorService,这个方法就是调用scheduledExecutorService.ScheduledExecutorService.shutdown();关掉线程的
  //
shutdown并不会直接关闭,它要等所有线程都执行完了,才会真的关掉,就是不打断关停。
//还有一个方法,shutdownNow()应该是立即关停。

}

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
        
    }
}

这个需要在web.xml里配置

    <listener> 
        <listener-class>com.feikantec.game.suit_tiles.utils.ServerContextManager</listener-class> 
    </listener> 

猜你喜欢

转载自www.cnblogs.com/angelshelter/p/8967717.html