George Sfiris opened SPR-15638 and commented
Description
There is a bug about Quartz Job Sheduler and Spring related Factory Beans. I noticed that there is a problem when overwriteExistingJobs=true and there is a Trigger which doesn't exist in the database but implicitly registers a JobDetails which exist in the database, as SchedulerFactoryBean fails to save or update both Trigger and JobDetails.
Steps to reproduce
- Create a Scheduler Bean using SchedulerFactoryBean
- set overwriteExistingJobs=true
- set datasource appropriately in order to store data in Database
- Register a SimpleTrigger with repeatInterval=1000 and repeatCount=5 (generally keep repeatCount and repeatInterval values low)
- In this trigger register implicitly a JobDetails with Durability=true (in order to retain this JobDetails in the Database)
- Register this trigger in SchedulerFactoryBean but not the JobDetails. (JobDetails will be implicitly registered through Trigger)
- Start the application
- You will notice that when SimpleTrigger reach the reapeatCount will be deleted from the database. But JobDetails will not as is marked with Durability=true
- Stop the appication and start it again
- You will notice that SimpleTrigger is not executed anymore.
- After this Register Explicitly the jobDetails in the SchedulerFactoryBean
- Run the application
- You will notice that SimpleTrigger is executed
In order to make it easier to reproduce this issue I created an example project spring-scheduling-implicit-job-registration-example in GitHub.
Sample Code
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="overwriteExistingJobs" value="true" />
<property name="dataSource" ref="dataSource" />
<property name="triggers">
<list>
<bean
class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="group" value="TEST" />
<property name="name" value="simple-trigger" />
<property name="startDelay" value="1000" />
<property name="repeatInterval" value="2000" />
<property name="repeatCount" value="5" />
<property name="jobDetail">
<bean class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="group" value="TEST" />
<property name="name" value="simple-trigger-job" />
<property name="jobClass"
value="my.package.SimpleTriggerJob" />
<property name="Durability" value="true" />
</bean>
</property>
</bean>
</list>
</property>
</bean>
<bean id="simpleTriggerJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="group" value="TEST" />
<property name="name" value="simple-trigger-job" />
<property name="jobClass"
value="my.package.SimpleTriggerJob" />
<property name="Durability" value="true" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="overwriteExistingJobs" value="true" />
<property name="dataSource" ref="dataSource" />
<property name="jobDetails">
<list>
<ref bean="simpleTriggerJob" />
</list>
</property>
<property name="triggers">
<list>
<bean
class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="group" value="TEST" />
<property name="name" value="simple-trigger" />
<property name="startDelay" value="1000" />
<property name="repeatInterval" value="2000" />
<property name="repeatCount" value="5" />
<property name="jobDetail" ref="simpleTriggerJob" />
</bean>
</list>
</property>
</bean>
Affects: 4.3.5, 4.3.6, 4.3.7, 4.3.8
Reference URL: https://github.com/george-sfiris/spring-scheduling-implicit-job-registration-example
Comment From: spring-projects-issues
George Sfiris commented
I should mention also a hint in the code which is the following SchedulerAccessor:308.
Comment From: snicoll
@george-sfiris sorry for the delay in triaging this issue. I am trying to access the sample but it does not seem to exist anymore. If you're still affected and can restore it with a supported version of spring framework, we can have look.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.