Reprint Please specify source: http://blog.csdn.net/l1028386804/article/details/46376093
1, the Scheduler configuration
<bean class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" > <property name= "triggers" > <list> <ref bean= "Testtrigger"/> </list> </property> < Property Name= "Autostartup" value= "true"/> </bean>
Description: Scheduler contains a list of trigger, each trigger represents a job.
2, the trigger configuration
<bean id= "Testtrigger" class= "Org.springframework.scheduling.quartz.CronTriggerBean" > <property Name = "Jobdetail" ref= "Testjobdetail"/> <property name= "cronexpression" value= "*/1 * * * * *?" /><!--triggered once every 1 seconds-
Description
1) Cron expression format: Second-time time-of-year (optional).
Allowed special characters for field name allowed values
Seconds 0-59,-*/
Sub 0-59,-*/
Hours 0-23,-*/
Day 1-31,-*? /L W C
Month 1-12 or JAN-DEC,-*/
How many weeks 1-7 or SUN-SAT,-*? /L C #
Year (optional field) empty, 1970-2099,-*/
“?” Character: Represents an indeterminate value
"," character: Specify a number of values
"-" character: Specifies the range of a value
"/" character: Specifies the increment of a value. N/m means starting with N, increasing m each time
"L" character: Used on the last day of the one month, used in the week to represent the last one weeks of the month X
"W" character: Specifies the most recent weekday from the given date (Monday to Friday)
The "#" character: The number of weeks that the month is X. 6#3 said the 3rd Friday of the Month
2) Cron Expression Example:
Execute once every 5 seconds: */5 * * * *?
Executes every 1 minutes: 0 */1 * * *?
Executed at 23 o ' Day: 0 0 23 * *?
Once daily 1 o'clock in the morning: 0 0 1 * *?
Every month, 1th, 1 o'clock in the morning, once: 0 0 1 1 *?
The last day of the month is executed at 23 points: 0 0 L *?
Once a week, Sunday 1 o'clock in the morning: 0 0 1? * L
At 26, 29, 33, execute once: 0 26,29,33 * * *?
Every day 0, 13, 18, 21 points are executed once: 0 0 0,13,18,21 * *?
3, the Jobdetail configuration
<bean id= "Testjobdetail" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" > <property name= "TargetObject" ref= "Testjob"/> <property name= "Targetmethod" value= "Execute"/> <property name= "concurrent" value= "false"/> <!--whether the task is allowed to execute concurrently. When the value is false, it means that you must wait until the previous thread has finished processing before starting a new thread- </bean>
4, the Business class configuration
<bean id= "Testjob" class= "Com.cjm.web.service.quartz.TestJob"/>
5. Business Class Source Code
public class Testjob {public void execute () { try{ //... } catch (Exception ex) { ex.printstacktrace ();}} }
Description: The business class does not need to inherit any parent class, nor does it need to implement any interfaces, just a common Java class.
Attention:
Two points to note when you configure and quartz integrated content in spring
1, in <Beans> can not set default-lazy-init= "true", otherwise the scheduled task does not trigger, if not explicitly indicate the value of Default-lazy-init, the default is False.
2, in <Beans> can not set the Default-autowire= "ByName" Properties, Otherwise the org.springframework.beans.factory.BeanCreationException error will be reported in the background, so that it cannot be injected automatically through the bean name and must be injected by explicit reference
Spring+quartz How to implement timed tasks (episode)