2011-08-28 29 views
6

Tôi chạy ứng dụng web dựa trên Spring Framework/SmartGWT, bây giờ đã thêm công việc Quartz. Công việc được cho là chạy mỗi ngày vào lúc 2 giờ sáng, và chọn người chiến thắng từ một bảng DB. Từ các bản ghi của tôi, tôi thấy nó chạy gấp đôi, đồng thời có vẻ như, bởi vì khi bạn có thể thấy, các bản ghi chồng lên nhau:Công việc Quartz chạy hai lần khi được triển khai trên 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 trông như thế này:

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

Tôi không thực sự xem có gì sai ở đây, nó là một trường hợp sử dụng khá đơn giản. Khi tôi thử nghiệm cục bộ này, trên máy chủ đi kèm với chế độ phát triển GWT, nó hoạt động. Chỉ khi triển khai vào Tomcat6 trên Ubuntu 10.04 LTS, tôi gặp vấn đề này.

Bất kỳ ý tưởng nào?

** chỉnh sửa: sau khi gợi ý từ nhận xét, tăng cấp độ nhật ký, có vẻ như Spring đang chạy hai lần. Khởi động lại máy chủ tomcat cho thấy hai Springs được khởi tạo, cách nhau khoảng 4 giây.

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 

Sau đó, hai trường hợp mùa xuân dường như được bắt đầu:

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 

gì có thể được gây ra điều này, và những gì cần phải làm?

+0

Có thể là một ý tưởng tốt để tăng mức độ đăng nhập của thạch anh một chút để xem liệu công việc có thực sự được lên lịch hai lần để thực thi hay không. – fvu

+0

Cảm ơn. Tôi đặt mức nhật ký mùa xuân để gỡ lỗi và có vẻ như mùa xuân chạy hai lần (Nhưng đó là ứng dụng duy nhất được triển khai)! Một trong hai lò xo chạy hai lần, HOẶC hạt lịch trình thạch anh được khởi tạo hai lần. Tôi đã đặt nhật ký trong câu hỏi trên –

+0

Tôi đã quan sát hành vi này mà không có thạch anh. Ngữ cảnh mùa xuân đã được nạp hai lần bất cứ khi nào tôi chạy ứng dụng trên Tomcat (ngay cả trên các cửa sổ từ bên trong netbeans). – kunal

Trả lời

7

Tôi đã sửa nó, không chỉ thạch anh chạy hai lần mà ứng dụng của tôi đã được triển khai hai lần. Điều này là do những điều sau trong tài liệu Tomcat:

Khi sử dụng triển khai tự động, docBase được định nghĩa bởi tệp Ngữ cảnh XML phải nằm ngoài thư mục appBase. Nếu đây không phải là trường hợp, khó khăn có thể có kinh nghiệm triển khai các ứng dụng web hoặc ứng dụng có thể được triển khai hai lần. Thuộc tính deployIgnore có thể được sử dụng để tránh tình trạng này.

Cuối cùng, lưu ý rằng nếu bạn đang xác định bối cảnh rõ ràng trong server.xml, có lẽ bạn nên tắt triển khai ứng dụng tự động hoặc chỉ định deployIgnore cẩn thận. Nếu không, các ứng dụng web sẽ được triển khai hai lần và có thể gây ra sự cố cho các ứng dụng.

Tôi đã làm theo hướng dẫn về cách làm việc với mod_jk và this tutorial chứa lỗ hổng đó.

0

Cuối cùng bạn có nhiều ứng dụng chạy bên trong một cá thể Tomcat trên máy Ubunut của bạn không? Tôi nghĩ rằng tôi nhớ Quartz để có một số mã tĩnh, mà nó sẽ chia sẻ througout tất cả các ứng dụng trong một máy ảo Java.

+0

Cảm ơn câu trả lời của bạn. Và có, tôi chỉ tìm ra rằng không chỉ thạch anh đã chạy hai lần, nhưng toàn bộ ứng dụng được triển khai hai lần. Xem câu trả lời của tôi dưới đây. –

3

Đối với tôi, việc triển khai tự động là vấn đề, và để vô hiệu hóa nó tôi đã phải chỉ định các thuộc tính sau trên các yếu tố chủ trong server.xml của tôi:

deployOnStartup="false" 
autoDeploy="false" 

Vì vậy, yếu tố chủ của tôi trông giống như này:

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

Tôi tìm thấy this post nêu chi tiết vấn đề theo cách khác giúp tôi giải quyết vấn đề này.

Các vấn đề liên quan