Scheduled jobs with Quartz scheduler with default values

admin

Administrator
Staff member
We have a web application running in Tomcat using Spring Framework. We need to add some scheduled jobs for recurrent operations. We came across Quartz Scheduler for this and followed a <a href="http://dimitrisli.wordpress.com/2010/09/20/spring-quartz-maven-example/" rel="nofollow">tutorial for configuring Jobs using Quartz with Spring</a> and got the jobs scheduled and running as expected.

So we have some tasks that are scheduled when the application starts. Now we want the user to manually run the jobs and change the trigger for the jobs, but we need that these changes are persisted to database. So when the application starts, it would read the persisted tasks and if they don't exist, load the default tasks from the spring descriptor file.

For simplicity's shake, let's assume that we're using the beans.xml file from the example:

Code:
&lt;bean id="processToExecute" class="com.mycompany.ProcessToExecute" /&gt;

&lt;bean name="processToExecuteJob" class="org.springframework.scheduling.quartz.JobDetailBean"&gt;
    &lt;property name="jobClass" value="com.mycompany.ProcessToExecuteJob" /&gt;
    &lt;property name="jobDataAsMap"&gt;
        &lt;map&gt;
            &lt;entry key="processToExecute" value-ref="processToExecute" /&gt;
        &lt;/map&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;
    &lt;property name="jobDetail" ref="processToExecuteJob" /&gt;
    &lt;property name="cronExpression" value="0/5 * * * * ?" /&gt;
&lt;/bean&gt;

&lt;bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;
    &lt;property name="jobDetails"&gt;
        &lt;list&gt;
            &lt;ref bean="processToExecuteJob" /&gt;
        &lt;/list&gt;
    &lt;/property&gt;
    &lt;property name="triggers"&gt;
        &lt;list&gt;
            &lt;ref bean="simpleTrigger" /&gt;
        &lt;/list&gt;
    &lt;/property&gt;
&lt;/bean&gt;

So we'd like to continue using beans-like configuration for default tasks but the option to load them from database if already scheduled.

Quartz here is not a requirement, if anyone knows a easier way to achieve it using Spring
Code:
@Scheduled
it could be useful too.

Thanks for your time.