定時批處理作業是J2EE企業應用里很重要的一環,用來在晚間進行財務掛賬,數據轉存,新聞聯播等等操作。
而在Spring里,已經很好的集成了Quartz,簡單到像配cron一樣,在xml文件里面配一下時間就可以自動執行,不需要寫一行代碼。
<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>
上面這段配置文件規定了在早上6點和晚上8點執行financeDAO對象的confirmOrder()方法
附:cronExpression配置說明
字段 | | 允許值 | | 允許的特殊字符 |
---|
秒 | | 0-59 | | , - * / |
分 | | 0-59 | | , - * / |
小時 | | 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)
評論(0) 編輯 收藏 所屬分類:
Open source