论坛首页 Java企业应用论坛

Scheduling with Spring

浏览 1460 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (17) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-07-02  
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>
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics