Spring Quartz多个并发作业执行

时间:2016-02-22 15:19:29

标签: java spring tomcat quartz-scheduler

我们有一个传统的单片应用程序,它使用 quartz 1.6.0 来运行作业。问题是每个作业同时运行4次。每个工作类都扩展org.springframework.scheduling.quartz.QuartzJobBean

我们在Tomcat 6上运行应用程序。

Some说这可能是一个tomcat问题,我已尝试设置autoDeploy="false"deployOnStartup="false",但无济于事。

有人说应用程序上下文被多次加载,但是当应用程序启动时,我只看到与石英相关的所有内容一次。

[2016-02-22 10:27:27,222] INFO  - org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(100) | Initializing EHCache CacheManager
[2016-02-22 10:27:27,227] INFO  - org.springframework.ws.soap.saaj.SaajSoapMessageFactory.afterPropertiesSet(123) | Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
[2016-02-22 10:27:27,256] INFO  - org.quartz.core.QuartzScheduler.<init>(209) | Quartz Scheduler v.1.6.0 created.
[2016-02-22 10:27:27,257] INFO  - org.quartz.simpl.RAMJobStore.initialize(141) | RAMJobStore initialized.
[2016-02-22 10:27:27,257] INFO  - org.quartz.impl.StdSchedulerFactory.instantiate(1208) | Quartz scheduler 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' initialized from an externally pr
ovided properties instance.
[2016-02-22 10:27:27,257] INFO  - org.quartz.impl.StdSchedulerFactory.instantiate(1212) | Quartz scheduler version: 1.6.0
[2016-02-22 10:27:27,257] INFO  - org.quartz.core.QuartzScheduler.setJobFactory(2065) | JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@bd65df9
[2016-02-22 10:27:27,258] INFO  - org.springframework.scheduling.quartz.SchedulerFactoryBean.startScheduler(626) | Starting Quartz Scheduler now
[2016-02-22 10:27:27,258] INFO  - org.quartz.core.QuartzScheduler.start(455) | Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED started.

我想修复重复问题,而不是同步代码中的内容。

我观察了方法调用链并意识到QuartzScheduler构造函数被调用了4次,调用如下:

DefaultListableBeanFactory.preInstantiateSingletons()
...
AbstractApplicationContext.refresh()
ContextLoader.createWebApplicationContext()
ContextLoader.initWebApplicationContext() 

对initWebApplicationContext的调用从:

开始
  1. 的ContextLoaderListener
  2. MessageDispatcherServlet x 2
  3. DipatcherServlet
  4. 这里是 web.xml

    <servlet>
        <servlet-name>spring-gui</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-gui</servlet-name>
        <url-pattern>....</url-pattern>
    </servlet-mapping>
    
    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>
            org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>...</url-pattern>
    </servlet-mapping>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/application-context.xml
        /WEB-INF/application-context-security.xml
        </param-value>
    </context-param>
    

    注意 application-context.xml 包含包含QuartzSchedulerFactory bean的bean文件。

    最明显的问题是Spring的配置错误。为什么app-context多次加载?配置Servlet和所有的正确方法是什么?

0 个答案:

没有答案