Scheduling with Spring

use spring's quartz to create a scheduling:
Quartz has the notion of four entities:a Job,  and a JobDetail, a Trigger, a Scheduler.

job:
<bean id="testService" class="test.TestService" >
</bean>
<!--Quartz jobs are not persisted by default. You need to implement the StatefulJob interface to have your jobs persisted between executions and between system restarts-->

JobDetail:
<bean id="testJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" scope="prototype">
<property name="targetObject">
<ref bean="testService" />
</property>
<property name="targetMethod">
<value>oneMethodInTestService</value>
</property>
<property name="concurrent">
                      <!--enforce that multiple instances of the job will not be executed concurrently-->
<value>false</value>
</property>
</bean>

Trigger:
  <bean id="testTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="testJobDetail" />
</property>
<property name="cronExpression">
                     <!--execution timing -->
<value>0/5 * * * * ?</value>
</property>
</bean>


Scheduler:
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="schedulerName" value="timesQuartz" />
<property name="autoStartup" value="true" />
<property name="triggers">
<list>
    <ref bean="testTrigger"/>
</list>
</property>
</bean>

你可能感兴趣的:(spring,quartz)