1. The class of the main method or the class that needs to perform the timed task plus @enablescheduling annotations
2. Timing Task method plus @scheduled annotations, plus time settings
3. There are two kinds of timing task time, one is to use fixedrate, one is con expression
3.1fixedRate usage such as:
@Scheduled (fixedrate = 1000 * 60)
The value of Fixedrate is the number of milliseconds of a long type;
This form of scheduled tasks is not flexible enough to be set according to the date.
3.2con expressions such as:
cron expression in detail a cron expression is a string of characters separated by 5 or 6 spaces, divided into 6 or 7 fields, each of which represents a meaning, and Cron has the following two syntax formats: Seconds Minutes Hours dayofmonth Month D Ayofweek year or Seconds Minutes Hours dayofmonth Month DayofWeek The characters that can appear in each field are as follows: Seconds: can appear", - * /"Four characters with a valid range of 0-integer Minutes of 59: can appear", - * /"Four characters with a valid range of 0-integer Hours of 59: can appear", - * /"Four characters with a valid range of 0-integer DayOfMonth of 23: can appear", - * / ? L W C"Eight characters with a valid range of 0-An integer of 31 Month: can appear", - * /"Four characters, integer or jan-with a valid range of 1-12DEc DayofWeek: can appear", - * / ? L C #"Four characters, integer or sun-with a valid range of 1-7sat two ranges. 1 means Sunday, 2 means Monday, and so on year: can appear", - * /"Four characters with a valid range of 1970-2099 each field uses numbers, but the following special characters can appear, meaning: (1*: Indicates any value that matches the field, if using * in the Minutes domain, which means that events are triggered every minute. (2): can only be used in DayOfMonth and DayOfWeek two domains. It also matches any value of the field, but it does not. Because DayOfMonth and DayOfWeek will affect each other. For example, to trigger a schedule on the 20th of each month, regardless of the day of the week on 20th, you can only use the following notation: - - the -*?, which the last one can only use? , and cannot use *, if used *This means that no matter what happens on the day of the week, it is not. (3)-: Indicates the range, for example, in the minutes domain using 5- -that is triggered every minute from 5 to 20 minutes (4)/: Indicates that the start time starts firing and then fires once every fixed time, for example, in the minutes domain using 5/ -, it means that 5 minutes is triggered once, and 25,45 is triggered separately. (5),: Indicates that the enumeration value values are listed. For example: Using 5 in the Minutes domain, -, it means firing at 5 and 20 minutes per minute. (6L: Indicates that finally, only in the DayOfWeek and dayofmonth domains, if 5L is used in the DayOfWeek domain, it means that it is triggered in the last Thursday. (7) W: Indicates a valid weekday (Monday to Friday) that can only appear in the DayOfMonth domain, and the system will trigger the event on the most recent active weekday from the specified date. For example: Use 5W in DayOfMonth, if 5th is Saturday, it will be triggered on the most recent weekday: Friday, 4th. If 5th is Sunday, it will be triggered on 6th (Monday) and if 5th is one day from Monday to Friday, it is triggered on 5th. Another point, W's recent search will not cross the month (8LW: These two characters can be used together, indicating the last working day of the month, that is, the last Friday. (9#: Used to determine the number of weeks per month and can only appear in the DayOfMonth domain. For example, in 4#2, which represents the second Wednesday of a month. For a few examples:0 0 2 1* ? *indicates that the task is scheduled 2 o'clock in the morning on the 1st of each month0 the Ten? * mon-FRI means that the job is performed 10:15 every day from Monday to Friday0 the Ten?6L 2002-2006Represents 2002-2006 Year last Friday 10:15 executes a cron expression with at least 6 (or possibly 7) time elements that have a space separation. Sequentially in order of seconds (0~ -) minutes (0~ -) hours (0~ at) days (months) (0~ to, but you need to consider the number of days of your month) months (0~ One) days (weeks) (1~7 1=SUN or Sun,mon,tue,wed,thu,fri,sat) year (1970-2099each of these elements can be a value (such as 6), a continuous interval (9- A), a time interval (8- -/4(/= every 4 hours), a list (1,3,5), a wildcard character. Because"date in the month"And"Day of the week"These two elements are mutually exclusive and must be set to one of them?0 0 Ten, -, -* * ?10 o'clock in the morning, 2 o'clock in the afternoon, 4 O ' Day0 0/ - 9- -* * ?every half hour for nine to five working hours0 0 A? *WED said every Wednesday noon 12 o'clock"0 0 * *?"triggered 12 o'clock noon every day"0. * *"triggered 10:15 daily"0 * *?"triggered 10:15 daily"0 * * *"triggered 10:15 daily"0 * * 2005"2005-year daily 10:15 trigger"0 * * *?"triggers every 1 minutes from 2 o'clock in the afternoon to 2:59 daily"0 0/5 * *?"triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily"0 0/5 14,18 * *?"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 * *?"triggers every 1 minutes from 2 o'clock in the afternoon to 2:05 daily"0 10,44 3 WED"every March, Wednesday, 2:10 and 2:44 triggers ."0. * Mon-fri"10:15 trigger from Monday to Friday"0 *?"15th 10:15 per month, triggered"0 L *?"10:15 trigger on the last day of the month"0. * 6L"last month of Friday 10:15 trigger"0. * 6L 2002-2005"2002 to 2005 the last Friday 10:15 trigger"0. * 6#3"Monthly third Friday 10:15 triggers some sub-expressions can contain ranges or lists such as: Sub-expressions (days (weeks)) can be "MON-fri "," Mon,wed,fri "," mon-Wed,sat ""*"The character represents all possible values, therefore,"* "in the sub-expression (month) means the meaning of each month," *"In a subexpression (Day (week)) represents every day of the week"/"character is used to specify the increment of a number, for example: in sub-expressions (minutes).0/ the"indicates that from the No. 0 minute, every 15 minutes in the sub-expression (minutes)"3/ -"represents every 20 minutes starting from the 3rd minute (IT and"3, at, +"The Meaning of")? "Character is used only for days (months) and days (weeks) two sub-expressions, indicating that no worth 2 sub-expressions are specified after one of the values has been specified, in order to avoid a conflict, the value of another subexpression needs to be set to"? The "L" character is used only for days (months) and days (weeks) of two sub-expressions, which is the abbreviation of the word "last" but it has a different meaning in two sub-expressions. In the day (month) subexpression, "L" means the last day of one months in the day (week) Self-expression, "L" represents the last day of one weeks, that is, if the SAT has specific content before "L", it has other meanings, for example: "6L"For the 6th day of the month," Fril "means the last Friday of the month. Note: When using the" L "parameter, do not specify a list or range, because this causes the problem field to allow special characters to be allowed in seconds0- -, - * /points0- -, - * /hours0- at, - * /Date1- to, - * ? /L W C Month1- Aor JAN-DEC,-*/Week1-7or Sun-sat,-*? /L C # year (optional) leave blank,1970-2099, - * /
0/5 * * * *? Triggered once every 5 seconds
0 0/1 * * *? Trigger once per minute
0 0/5 * * *? Triggered once every five minutes
0 0 0/1 * *? Trigger once per hour
4. Time zone settings such as:
@Scheduled (cron= "0 0/1 * * * *?", zone= "Asia/shanghai")
Spring Schedule timed Tasks