Spring quartz scheduled task

Source: Internet
Author: User

1: first, make sure that a spring web project can run. The spring version is 3.1, and the usage of 3.0 is somewhat different.

The quartz version is 2.0.2.

Throughout to run in addition to spring essential package but also quartz-all-2.0.2.jar, slf4j-api-1.6.4.jar

Please note that CronTriggerBean is used on the Internet. I tested the error and CronTriggerFactoryBean is used here.

Org. springframework. scheduling. quartz. CronTriggerFactoryBean


2: Add the following configuration in applicationContext. xml

<! -- Scheduled task class start -->
<Bean id = "jobClass" class = "com. ws. quartz. TestQuartz"> </bean>
<Bean name = "initTask" class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<Property name = "targetObject">
<Ref bean = "jobClass"/>
</Property>
<Property name = "targetMethod">
<Value> jobDetail </value>
</Property>
</Bean>
<Bean id = "cronTrigger" class = "org. springframework. scheduling. quartz. CronTriggerFactoryBean">
<Property name = "jobDetail">
<Ref bean = "initTask"/>
</Property>
<Property name = "cronExpression" value = "10, 15, 20, 25, 30, 35, 40, 45, 50, 55 ****? "/>
</Bean>
<Bean id = "start" lazy-init = "false" autowire = "no"
Class = "org. springframework. scheduling. quartz. SchedulerFactoryBean">
<Property name = "triggers">
<List>
<Ref bean = "cronTrigger"/>
</List>
</Property>
</Bean>
<! -- Scheduled task class end -->

--------------------- A method in the class

Public class TestQuartz {

Public void jobDetail (){
System. out. println ("scheduled task ");
}
}

Ps: In this example, the jobDetail method is executed every five seconds, and "scheduled task" is continuously played on the console"

This article from the "unemployed Travel" blog, please be sure to keep this source http://2820354.blog.51cto.com/2810354/1302162

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.