quartz + spring 启动项目时,报错The web application [] appears to have started a thread named............

  只是想记录自己的错误信息,下次再出现就知道怎么操作,不用再查找资料

解决办法:

package com.wqq.quartz_test.schedule;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;

/** 
 * @author wangqq 
 * @version 创建时间:2018年9月14日 上午9:49:29 
 * 类说明 
 */
public class QuartzContextListener implements ServletContextListener {

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

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
        WebApplicationContext webApplicationContext = (WebApplicationContext) arg0
                .getServletContext()
                .getAttribute(
                        WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        org.quartz.impl.StdScheduler startQuertz = (org.quartz.impl.StdScheduler) webApplicationContext
                .getBean("startQuertz");
        if(startQuertz != null) {
            startQuertz.shutdown();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

其中 

"startQuertz" 是在spring-quartz.xml中
 <bean id="startQuartz" lazy-init="false" autowire="no" 
          class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="jobTriggerA"/>
                <ref bean="jobTriggerB"/>
            </list>
        </property>
         <property name="quartzProperties">  
            <props>  
                <prop key="org.quartz.scheduler.instanceName">buy_it_now</prop>
                <prop key="org.quartz.threadPool.threadCount">2</prop>  
                <prop key="org.quartz.plugin.shutdownhook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
                <prop key="org.quartz.plugin.shutdownhook.cleanShutdown">true</prop>
                <prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
            </props>  
        </property> 
        <property name="configLocation" value="classpath:quartz/quartz.properties"></property>
        <property name="applicationContextSchedulerContextKey" value="applicationContext" />
    </bean>

然后在web.xml中配置

<listener>
      <listener-class>com.wqq.quartz_test.schedule.QuartzContextListener</listener-class>
  </listener>

虽然不报错了,但是把这个注释掉,也不报错了,不知道程序发什么疯,可能有些原理还不知道

转载于:https://www.cnblogs.com/Cassie-wang/p/9646864.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值