zoukankan      html  css  js  c++  java
  • 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>

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

  • 相关阅读:
    循环事件绑定和原型的应用
    小知识随手记(四)
    JavaScript数组与字符串常用方法总结
    jquery获得select option的值和对select option的操作
    前端图片上传前预览
    CSS 的优先级机制总结
    汇编语言学习笔记(8)——数据处理的基本问题
    SPOJ 1811LCS Longest Common Substring
    mysql 安装完毕后登陆不了mysql的 shell 即mysql&gt;遇到:ERROR 1045 (28000): Access denied for user 'root'@'localhost‘
    [LeetCode]Power of Two
  • 原文地址:https://www.cnblogs.com/Cassie-wang/p/9646864.html
Copyright © 2011-2022 走看看