1 web项目, 关闭tomcat,里面的多线程不关闭
private static ScheduledExecutorService service= Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t=new Thread(r, "Checker"); return t; } });
2 解决办法 参考 http://www.cnblogs.com/eczhou/archive/2012/03/26/2418201.html 2.1 web.xml添加 <listener> <listener-class>com.****.web.Listener</listener-class> </listener>
2.2
public class Listener implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("Listener: destroy================");
try{
XXXXcontainer.destroy();
}catch (Exception e) {
System.out.println("error:"+e.getMessage());
// logger.error(e.getMessage(),e); System.exit(1); } }
@Override
public void contextInitialized(ServletContextEvent arg0){
System.out.println("Listener: init================");
}
}
3
使用Executors建立后台线程并执行一些多线程操作时,Executors会使用相对应的threadFactory来对 runnable建立新的thread,所以使用默认的threadFactory时就会出问题。默认的ThreadFactory强制性的将新创建的线程设置为非守护状态,