Configuration of 1.Scheduler
<BeanID= "Myscheduler"class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean"> < Propertyname= "Triggers"> <List> <refBean= "Mytriggersa"></ref> <refBean= "MYTRIGGERSB"></ref> </List> </ Property> < Propertyname= "Autostartup"value= "true"></ Property> </Bean>
Configuration of 2.Trigger
<BeanID= "Mytriggersa"class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean"> < Propertyname= "Jobdetail"ref= "Myjobdetaila"> </ Property> < Propertyname= "Cronexpression"> <value>0/1 * * * *?</value> </ Property> </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 * *?
"0 0 12 * *?" trigger 12 o'clock noon every day.
"0 15 10?" * * "trigger 10:15 every day"
"0 15 10 * *?" Daily 10:15 Trigger
"0 15 10 * *?" * "10:15 per day" trigger
"0 15 10 * *?" 2005 "2005-year daily 10:15 Trigger
"0 * 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:59 daily
"0 0/5 14 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily
"0 0/5 14,18 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily and from 6 o'clock in the afternoon to 6:55
"0 0-5 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:05 daily
"0 10,44 14?" 3 WED "2:10 and 2:44 triggers in Wednesday of every March
"0 15 10?" * Mon-fri "Monday to Friday 10:15 trigger
"0 15 10 15 *?" 15th 10:15 per month
"0 L *?" 10:15 on the last day of the month
"0 15 10?" * 6L "Last month of Friday 10:15 Trigger
"0 15 10?" * 6L 2002-2005 "2002 to 2005 the last of the monthly Friday 10:15 trigger
"0 15 10?" * 6#3 "Monthly third Friday 10:15 trigger
Every morning at 6.
0 6 * * *
Every two hours
0 */2 * * *
Every two hours between 11 o'clock and 8 in the morning, eight in the morning.
0 23-7/2,8 * * *
Every month, number 4th and Monday to Sunday, three a.m., 11.
0 11 4 * 1-3
January 1 morning, 4.
0 4 1 1 *
Configuration of 3.JobDetail
<BeanID= "Myjobdetaila"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> < Propertyname= "TargetObject"ref= "Myjoba"> </ Property> < Propertyname= "Targetmethod"value= "Work"></ Property> < 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. Configuration of the Business class
<id= "Myjoba" class= "Com.quartz.MyJobA"> </bean>
5. Business Class Code
Import java.util.Date; Public class Myjoba { publicvoid work () { System.out.println (new Date (). GetTime ());} }
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.
Spring+quartz implementation of timing task configuration method