定時(shí)批處理作業(yè)是J2EE企業(yè)應(yīng)用里很重要的一環(huán),用來(lái)在晚間進(jìn)行財(cái)務(wù)掛賬,數(shù)據(jù)轉(zhuǎn)存,新聞聯(lián)播等等操作。
而在Spring里,已經(jīng)很好的集成了Quartz,簡(jiǎn)單到像配cron一樣,在xml文件里面配一下時(shí)間就可以自動(dòng)執(zhí)行,不需要寫一行代碼。
<bean id="methodInvokingJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject"><ref bean="financeDAO"/></property>
<property name="targetMethod"><value>confirmOrder</value></property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail"><ref bean="methodInvokingJobDetail"/></property>
<property name="cronExpression"><value>0 0 6,12,20 * * ?</value></property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers"><list><ref local="cronTrigger"/></list></property>
</bean>
上面這段配置文件規(guī)定了在早上6點(diǎn)和晚上8點(diǎn)執(zhí)行financeDAO對(duì)象的confirmOrder()方法
附:cronExpression配置說(shuō)明
字段 | | 允許值 | | 允許的特殊字符 |
---|
秒 | | 0-59 | | , - * / |
分 | | 0-59 | | , - * / |
小時(shí) | | 0-23 | | , - * / |
日期 | | 1-31 | | , - * ? / L W C |
月份 | | 1-12 或者 JAN-DEC | | , - * / |
星期 | | 1-7 或者 SUN-SAT | | , - * ? / L C # |
年(可選) | | 留空, 1970-2099 | | , - * / |
posted on 2005-02-04 11:16
jacky 閱讀(414)
評(píng)論(0) 編輯 收藏 所屬分類:
Open source