1, the Scheduler configuration
<Beanclass= "Org.springframework.scheduling.quartz.SchedulerFactoryBean"> < Propertyname= "Triggers"> <List> <refBean= "Testtrigger"/> </List> </ Property> < Propertyname= "Autostartup"value= "true"/> </Bean>
Description: Scheduler contains a list of trigger, each trigger represents a job.
2, the trigger configuration
<BeanID= "Testtrigger"class= "Org.springframework.scheduling.quartz.CronTriggerBean"> < Propertyname= "Jobdetail"ref= "Testjobdetail"/> < Propertyname= "Cronexpression"value= "*/1 * * * *?"/><!--trigger once every 1 seconds -</Bean>
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
<BeanID= "Testjobdetail"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> < Propertyname= "TargetObject"ref= "Testjob"/> < Propertyname= "Targetmethod"value= "Execute"/> < Propertyname= "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
<id= "Testjob" class= "Com.cjm.web.service.quartz.TestJob " />
5. Business Class Source code
Public class testjob { publicvoid 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, or the background will be reported org.springframework
Spring+quartz implementation of timing task configuration method