2011-08-28 11 views
6

Prowadzę aplikację internetową Spring Framework/SmartGWT, z dodatkowym zadaniem Quartz. Praca ma być uruchamiana codziennie o 2 nad ranem i wybiera zwycięzców z tabeli DB. Z moich dziennikach widzę to działa dwukrotnie, jednocześnie wydaje się, bo jak widać, do którego loguje się pokrywają:Zadanie kwarcowe działa dwa razy po wdrożeniu na platformie tomcat 6/Ubuntu 10.04LTS

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. 

My applicationContext.xml wygląda następująco:

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

ja naprawdę nie zobacz, co tu jest nie tak, jest to całkiem prosty przypadek użycia. Kiedy testuję to lokalnie, na serwerze, który jest wyposażony w tryb programowania GWT, to działa. Tylko podczas wdrażania do Tomcat6 na Ubuntu 10.04 LTS pojawia się ten problem.

Wszelkie pomysły?

** edycja: po podpowiedzi od komentarzy, zwiększenie poziomu dziennika, wydaje się, że Spring działa dwa razy. Ponowne uruchomienie serwera tomcat pokazuje, że tworzone są dwa Źródła, w odległości około 4 sekund.

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 

Później dwie instancje Wiosna wydaje się być uruchomiony:

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 

Co może być tego przyczyną i co należy zrobić?

+0

Dobrym pomysłem może być zwiększenie poziomu rejestrowania kwarcu, aby sprawdzić, czy zadanie rzeczywiście zostanie zaplanowane dwukrotnie w celu wykonania. – fvu

+0

Dzięki. Ustawiłem poziom logu sprężynowego do debugowania i wygląda to tak, jakby dwukrotnie uruchamiała się wiosna (ale jest to jedyna wdrożona aplikacja)! Każda sprężyna działa dwukrotnie, LUB kwarcowy moduł harmonogramu jest tworzony dwukrotnie. Umieściłem dziennik w pytaniu powyżej –

+0

Obserwowałem to zachowanie również bez kwarcu. Kontekst sprężynowy był ładowany dwa razy, gdy tylko uruchomiłem aplikację na Tomcat (nawet w oknach z poziomu netbeans). – kunal

Odpowiedz

7

Naprawiłem, nie tylko kwarc działał dwa razy, ale moja aplikacja została wdrożona dwa razy. Stało się tak z powodu następujących dokumentów Tomcat:

Podczas korzystania z automatycznego wdrażania, dokumentacja zdefiniowana przez plik XML Context powinna znajdować się poza katalogiem appBase. Jeśli tak nie jest, mogą wystąpić trudności z wdrożeniem aplikacji internetowej lub aplikacja może zostać wdrożona dwukrotnie. W celu uniknięcia tej sytuacji można użyć atrybutu deployIgnore.

Wreszcie, jeśli definiujesz konteksty jawnie w pliku server.xml, prawdopodobnie powinieneś wyłączyć automatyczne wdrażanie aplikacji lub dokładnie określić opcję wdrażania wdrożeń. W przeciwnym razie aplikacje internetowe będą wdrażane dwukrotnie, co może powodować problemy dla aplikacji.

Poszedłem za tutorialem, jak uzyskać dostęp do mod_jk, a this tutorial zawierał tę wadę.

0

Czy masz w końcu wiele aplikacji działających w jednej instancji Tomcat na twoim komputerze Ubunut? Myślę, że pamiętam Quartz, że ma jakiś statyczny kod, który będzie się dzielić przez wszystkie aplikacje w jednej maszynie wirtualnej Java.

+0

Dzięki za odpowiedź. I tak, właśnie odkryłem, że nie tylko kwarc działa dwa razy, ale cała aplikacja została wdrożona dwa razy. Zobacz moją odpowiedź poniżej. –

3

Dla mnie, rozmieszczenie auto był problem, i aby ją wyłączyć musiałem podać następujące atrybuty na gospodarza elementu w moim server.xml:

deployOnStartup="false" 
autoDeploy="false" 

Więc mój żywioł gospodarz wyglądał to:

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

znalazłem this post szczegółowo ten problem w inny sposób, który pomógł mi rozwiązać ten problem.