部署在tomcat 6/Ubuntu 10.04LTS上的Quartz作业运行两次 [英] Quartz job runs twice when deployed on tomcat 6/Ubuntu 10.04LTS

查看:83
本文介绍了部署在tomcat 6/Ubuntu 10.04LTS上的Quartz作业运行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了一个基于Spring Framework/SmartGWT的Web应用程序,现在添加了一个Quartz作业.该工作应该每天凌晨2点运行,并从数据库表中挑选赢家.从我的日志中,我看到它同时运行两次,因为如您所见,日志重叠:

I run a Spring Framework/SmartGWT based web-app, with now an added Quartz job. The job is supposed to run every day at 2am, and picks winners from a DB table. From my logs I see it runs twice, concurrently it seems, because as you can see, the logs overlap:

Generating winners of yesterday...
Generating winners of yesterday...
winning id's: 15
done, mail queue is filled.

winning id's: 18
done, mail queue is filled.

我的applicationContext.xml看起来像这样:

My applicationContext.xml looks like this:

<!-- initiates and calls the job -->  
<beans:bean id="GenerateWinnersAndFillMailingQueueJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 
  <beans:property name="targetObject" ref="GenerateWinnersAndFillMailingQueueJobExecutor"/>  
  <beans:property name="targetMethod" value="execute"/> 
</beans:bean>  
<!-- here's where we use the Cron like scheduling expression      to define when the bean is run. -->  
<beans:bean id="GenerateWinnersAndFillMailingQueueJob" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
  <beans:property name="jobDetail" ref="GenerateWinnersAndFillMailingQueueJobDetail"/>  
  <!-- run every morning at 2AM -->  
  <beans:property name="cronExpression" value="0 0 2 * * ?"/> 
</beans:bean> 
... another quartz jobs is defined here, omitted for clarity ...
<beans:bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
  <beans:property name="triggers"> 
    <beans:list> 
      <beans:ref bean="GenerateWinnersAndFillMailingQueueJob"/>  
      <beans:ref bean="SendEmailsFromMailQueueJob"/> 
    </beans:list> 
  </beans:property> 
</beans:bean> 

我真的不明白这里有什么问题,这是一个非常简单的用例.当我在本地测试时,在GWT开发模式附带的服务器上,它确实起作用.仅当在Ubuntu 10.04 LTS上部署到Tomcat6时,才会出现此问题.

I don't really see what is wrong here, it is a pretty simple use case. When I test this locally, on the server that comes with GWT development mode, it DOES work. Only when deploying to Tomcat6 on Ubuntu 10.04 LTS, I get this issue.

有什么想法吗?

**在注释提示之后,增加了日志级别,看来Spring运行了两次.重新启动tomcat服务器显示实例化了两个Spring,相隔约4秒.

** edit: after a hint from the comments, increasing the log level, it seems that Spring is running twice. Restarting the tomcat server shows that two Springs are instantiated, about 4 seconds apart.

2011-08-29 08:49:22,567 {ABSOLUTE}  INFO XmlWebApplicationContext,Thread-9:1002 - Closing Root WebApplicationContext: startup date [Sun Aug 28 20:53:39 CEST 2011]; root of context hierarchy
2011-08-29 08:49:22,569 {ABSOLUTE}  INFO DefaultLifecycleProcessor,Thread-9:345 - Stopping beans in phase 2147483647
2011-08-29 08:49:22,589 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:537 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED paused.
2011-08-29 08:49:22,592 {ABSOLUTE}  INFO DefaultListableBeanFactory,Thread-9:422 - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12e14ebc: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,MerchantSimpleJsonWebservice,merchantDao,AdvertisementSimpleJsonWebservice,advertisementDao,ContactFormSubmitsSimpleJsonWebservice,contactFormSubmitsDao,PlayerCustomJsonWebservice,PlayerCustomJsonWebserviceImpl,submitSolutionDao,GenerateWinnersAndFillMailingQueueJobExecutor,GenerateWinnersAndFillMailingQueueJobDetail,GenerateWinnersAndFillMailingQueueJob,SendEmailsFromMailQueueJobExecutor,SendEmailsFromMailQueueJobDetail,SendEmailsFromMailQueueJob,org.springframework.scheduling.quartz.SchedulerFactoryBean#0,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.config.http.UserDetailsServiceInjectionBeanPostProcessor#0,org.springframework.security.filterChainProxy,sessionAuthenticationStrategy,sessionRegistry,propertyConfigurer,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,saltSource,dataSource,jdbcTemplate,passwordEncoder,jdbcUserService,loggerListener,formLoginFilter,authenticationEntryPoint,accessDeniedHandler,concurrencyFilter]; root of factory hierarchy
2011-08-29 08:49:22,601 {ABSOLUTE}  INFO SchedulerFactoryBean,Thread-9:760 - Shutting down Quartz Scheduler
2011-08-29 08:49:22,601 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:616 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED shutting down.
2011-08-29 08:49:22,602 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:537 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED paused.
2011-08-29 08:49:22,603 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:688 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED shutdown complete.
2011-08-29 08:49:22,882 {ABSOLUTE}  INFO XmlWebApplicationContext,Thread-9:1002 - Closing Root WebApplicationContext: startup date [Sun Aug 28 20:53:34 CEST 2011]; root of context hierarchy
2011-08-29 08:49:22,883 {ABSOLUTE}  INFO DefaultLifecycleProcessor,Thread-9:345 - Stopping beans in phase 2147483647
2011-08-29 08:49:22,903 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:537 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED paused.
2011-08-29 08:49:22,904 {ABSOLUTE}  INFO DefaultListableBeanFactory,Thread-9:422 - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@402fb002: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,MerchantSimpleJsonWebservice,merchantDao,AdvertisementSimpleJsonWebservice,advertisementDao,ContactFormSubmitsSimpleJsonWebservice,contactFormSubmitsDao,PlayerCustomJsonWebservice,PlayerCustomJsonWebserviceImpl,submitSolutionDao,GenerateWinnersAndFillMailingQueueJobExecutor,GenerateWinnersAndFillMailingQueueJobDetail,GenerateWinnersAndFillMailingQueueJob,SendEmailsFromMailQueueJobExecutor,SendEmailsFromMailQueueJobDetail,SendEmailsFromMailQueueJob,org.springframework.scheduling.quartz.SchedulerFactoryBean#0,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.config.http.UserDetailsServiceInjectionBeanPostProcessor#0,org.springframework.security.filterChainProxy,sessionAuthenticationStrategy,sessionRegistry,propertyConfigurer,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,saltSource,dataSource,jdbcTemplate,passwordEncoder,jdbcUserService,loggerListener,formLoginFilter,authenticationEntryPoint,accessDeniedHandler,concurrencyFilter]; root of factory hierarchy
2011-08-29 08:49:22,913 {ABSOLUTE}  INFO SchedulerFactoryBean,Thread-9:760 - Shutting down Quartz Scheduler
2011-08-29 08:49:22,914 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:616 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED shutting down.
2011-08-29 08:49:22,914 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:537 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED paused.
2011-08-29 08:49:22,915 {ABSOLUTE}  INFO QuartzScheduler,Thread-9:688 - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED shutdown complete.
2011-08-29 08:49:26,484 {ABSOLUTE}  INFO ContextLoader,main:187 - Root WebApplicationContext: initialization started

后来,似乎启动了两个Spring实例:

Later on, two Spring instances seem to be started:

2011-08-29 08:49:26,484 {ABSOLUTE}  INFO ContextLoader,main:187 - Root WebApplicationContext: initialization started
...
2011-08-29 08:49:31,221 {ABSOLUTE}  INFO ContextLoader,main:187 - Root WebApplicationContext: initialization started

这是什么原因导致的,该怎么办?

What can be causing this, and what's to be done?

推荐答案

我修复了它,不仅石英运行了两次,而且我的应用程序也部署了两次.这是因为Tomcat文档中的以下内容:

I fixed it, not only quartz was running twice, but my app was deployed twice. This was because of the following in the Tomcat docs:

使用自动部署时,由XML上下文文件定义的docBase应该在appBase目录之外.如果不是这种情况,则部署Web应用程序可能会遇到困难,或者应用程序可能会部署两次. deployIgnore属性可用于避免这种情况.

When using automatic deployment, the docBase defined by an XML Context file should be outside of the appBase directory. If this is not the case, difficulties may be experienced deploying the web application or the application may be deployed twice. The deployIgnore attribute can be used to avoid this situation.

最后,请注意,如果要在server.xml中显式定义上下文,则可能应关闭自动应用程序部署或仔细指定deployIgnore.否则,每个Web应用程序将被部署两次,这可能会导致应用程序出现问题.

Finally, note that if you are defining contexts explicitly in server.xml, you should probably turn off automatic application deployment or specify deployIgnore carefully. Otherwise, the web applications will each be deployed twice, and that may cause problems for the applications.

我遵循了有关如何使mod_jk工作的教程,并且

I followed a tutorial on how to get mod_jk working, and this tutorial contained that flaw.

这篇关于部署在tomcat 6/Ubuntu 10.04LTS上的Quartz作业运行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆