appears to have started a thread named [startQuertz_xxx] but has failed to stop it. This is very...

quartz2.2.1 + spring3.2做定时任务的时候 , tomcat7重启/关闭服务出现如下异常:


idea:服务无法重启,提示JMX port:1099,已使用。


eclipse:服务可以重启,但是时间一久后台会有大量线程占用数据库连接。

appears to have started a thread named [startQuertz_xxx] but has failed to stop it. This is very..._第1张图片


原因:

          tomcat在shutdown做清理工作的时候没能等待quartz完成cleanShutdown工作时就已经关闭 !


解决方案:自己实现ServletContextListener

/**
 *@User only29
 *@Date 2014-12-24
 *@Time 上午11:35:48
 * 没等quartz clean关闭时,tomcat已经关闭了,导致quartz线程一直占用着8080/jxm port:1099端口
 */
public class QuartzContextListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent event) {
        try{
           Scheduler startQuartz = (Scheduler) WebApplicationContextUtils
                    .getWebApplicationContext(event.getServletContext())
                    .getBean("startQuartz");

            if(startQuartz != null){
                startQuartz.shutdown(true);
            }

            Thread.sleep(1000);//主线程睡眠1s
        }catch (Exception e){
            e.printStackTrace();
        }
        event.getServletContext().log("QuartzContextListener销毁成功!");
        System.out.println("QuartzContextListener销毁成功!");
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
        System.out.println("QuartzContextListener启动成功!");
		event.getServletContext().log("QuartzContextListener启动成功!");
	}
}

web.xml添加


  xxx.xxx.xxx.QuartzContextListener



参考来自:http://blog.csdn.net/huilixiang/article/details/8730520


你可能感兴趣的:(Exception)