2011-08-28 14 views
6

Spring Framework/SmartGWTベースのweb-appを実行し、Quartzジョブが追加されました。仕事は毎日午前2時に実行され、DBテーブルから勝者を選ぶ予定です。私は本当にないtomcat 6/Ubuntu 10.04LTSにデプロイするとQuartzジョブが2回実行される

<!-- 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> 

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を、次のようになります。私のログから、私はあなたが見ることができるように、ログが重複するので、それは、それはそう同時に、二回実行されます参照します何がここで間違っているかを見てください、それはかなり簡単なユースケースです。これをローカルでテストすると、GWT開発モードに付属するサーバー上で動作します。 Ubuntu 10.04 LTSでTomcat6にデプロイする場合にのみ、この問題が発生します。

アイデア?

**編集:コメントのヒントの後、ログレベルを上げると、Springが2回実行されているようです。 Tomcatサーバーを再起動すると、約4秒間隔で2つのスプリングがインスタンス化されます。

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 
この原因することができますどのような

、そして何がだが行われる。

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.s[email protected]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.s[email protected]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 

は後で、2つの春のインスタンスが開始されているように見えますか?

+0

クォーツのロギングレベルを少し上げて、ジョブが実際に実行のために2回スケジューリングされるかどうかを確認することをお勧めします。 – fvu

+0

ありがとうございます。私は春のログレベルをデバッグするようにしていますが、春の実行は2回に見えます(ただし、デプロイされた唯一のアプリです)!スプリングが2回実行されるか、石英スケジューラーBeanが2回インスタンス化されます。私は上の質問にログを入れました –

+0

私は石英なしでもこの現象を観察しました。私がTomcat(ネットビーン内のウィンドウでさえ)上でアプリケーションを走らせるときはいつも、スプリングコンテキストは2回ロードされていました。 – kunal

答えて

7

私はそれを修正しました。クォーツは2回だけでなく、2回展開されました。これは、Tomcatのドキュメントに以下であった:

自動展開を使用して、XMLコンテキストファイルで定義された文書ベースは、外のappBaseディレクトリのでなければなりません。これが当てはまらない場合は、Webアプリケーションのデプロイメントが困難な場合や、アプリケーションを2回デプロイする場合があります。この状況を回避するには、deployIgnore属性を使用できます。

最後に、server.xmlでコンテキストを明示的に定義する場合は、アプリケーションの自動デプロイメントを無効にするか、deployIgnoreを慎重に指定する必要があります。そうしないと、Webアプリケーションがそれぞれ2回展開され、アプリケーションに問題が発生する可能性があります。

私はmod_jkを動作させる方法についてのチュートリアルに続き、this tutorialにこの欠陥が含まれていました。だから私のホスト要素は、ように見えた

deployOnStartup="false" 
autoDeploy="false" 

:私にとって

0

最終的にUbunutマシン上の1つのTomcatインスタンス内で複数のアプリケーションを実行していますか?私は、Quartzが静的なコードを持っていることを覚えていると思います.1つのJava VMですべてのアプリケーションを共有します。

+0

あなたの答えをありがとう。そして、はい、私はちょうどクォーツが2回実行されているだけでなく、アプリ全体が2回展開されていることを理解しました。下の私の答えを見てください。 –

3

は、自動展開が問題であり、それを無効にするために、私は私のserver.xmlのホスト要素に次の属性を指定する必要がありましたこの:

<Host name="localhost" 
     deployOnStartup="false" 
     appBase="webapps" 
     unpackWARs="false" 
     autoDeploy="false"> 

私はthis postは私がこの問題を解決する助け、別の方法で問題を詳述しました。

関連する問題