Scheduled batch processing is an important part of J2EE enterprise applications. It is used for financial accounting, data transfer, news broadcast, and other operations at night.
In spring, quartz has been well integrated. Just like Cron, it can be automatically executed with a time in the XML file without writing a line of code. Spring's drastic simplification of quartz is an example. The quartz project team may be able to learn about it.
<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>
The preceding configuration file specifies that the confirmorder () method of the financedao object is executed at AM and AM.
Appendix: cronexpression configuration instructions
Field |
|
Allowed value |
|
Special characters allowed |
Seconds |
|
0-59 |
|
, - * / |
Minute |
|
0-59 |
|
, - * / |
Hours |
|
0-23 |
|
, - * / |
Date |
|
1-31 |
|
, - * ? / L W C |
Month |
|
1-12 or JAN-DEC |
|
, - * / |
Week |
|
1-7 or sun-Sat |
|
, - * ? / L C # |
Year (optional) |
|
Leave blank. values range from 1970 to 2099. |
|
, - * / |