Spring-use quartz to implement scheduled jobs

Source: Internet
Author: User

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. , - * /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.