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>

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

  • 相关阅读:
    小师妹学JVM之:JDK14中JVM的性能优化
    小师妹学JVM之:深入理解JIT和编译优化-你看不懂系列
    小师妹学JVM之:GC的垃圾回收算法
    小师妹学JVM之:JVM的架构和执行过程
    小师妹学JavaIO之:用Selector来发好人卡
    小师妹学JavaIO之:NIO中那些奇怪的Buffer
    小师妹学JavaIO之:MappedByteBuffer多大的文件我都装得下
    小师妹学JavaIO之:NIO中Channel的妙用
    小师妹学JavaIO之:Buffer和Buff
    小师妹学JavaIO之:文件File和路径Path
  • 原文地址:https://www.cnblogs.com/Cassie-wang/p/9646864.html
Copyright © 2011-2022 走看看