There is a task in Spring, which is a set-time automatic task scheduling that Spring brings with it.
task is easy to use, but it can do less than quartz!
You can use annotations and configuration in the following ways
Introduce Spring at the beginning of appcation.xml
Registered bean s
<! - - - Open Task Scheduling - > Open Task Scheduling
The first task represents calling the execute method in the voiceFileClearJob class five seconds after the program starts, and then calling execute again every hour.
The third task represents a daily call to the statLgj method in the statJob class at 23:59
ref is a working class
Method is the method to be executed in the working class
initial-delay is the delay in milliseconds before the task is first invoked.
fixed-delay is the delay of calling again after the last call is completed
fixed-rate is the delay of calling again after the last call starts (without waiting for the last call to complete)
cron is an expression that indicates when a task is scheduled.
Following is the code of the versionListenJob class mentioned above. The function is to monitor a folder. If there are any changes in the contents of the folder, a txt file will be regenerated. The file records the relevant information of all the files in the folder.
A cron expression has at least six (or possibly seven) space-separated time elements.
In order of order, the following is the order of uuuuuuuuuuu
Second (0-59)
Minutes (0-59)
Hours (0-23)
Days (months) (0-31, but you need to consider the number of days in your month)
Month (0-11)
Day (week) (1-7 1 = SUN or SUN, MON, TUE, WED, THU, FRI, SAT)
Year (1970-2099)
Each element can be a value (e.g. 6), a continuous interval (9-12), an interval (8-18/4) (/ representing every four hours), a list (1, 3, 5), wildcards. Because "Date in Month" and "Date in Week" are mutually exclusive, one of them must be set?
00 10, 14, 16*? Every day at 10 a.m., 2 p.m., 4 p.m.
0/309-17*? Every half hour during the nine-to-five working hours
0012?* WED means 12 noon every Wednesday.
"0 02 * *?" Triggered at 12 noon every day.
"0 1510?*" is triggered at 10:15 a.m. every day.
"0 1510 * *?" Triggered at 10:15 a.m. every day.
"0 1510 *?*" is triggered at 10:15 a.m. every day.
"0 1510 *? 2005" triggered at 10:15 a.m. in 2005
"0 * 14 *?" Triggered every minute from 2 p.m. to 2 p.m. at 2:59 p.m.
"0/514* *?" Triggered every five minutes between 2 p.m. and 2:55 p.m. every day.
"0/514, 18* *?" Triggered every five minutes between 2 p.m. and 2:55 p.m. and between 6 p.m. and 6:55 p.m.
"0-5 14* *?" Triggered every minute between 2 p.m. and 2 p.m. every day.
"0 10,44 14?3 WED" is triggered at 2:10 and 2:44 p.m. on Wednesday, March each year.
"0 1510?* MON-FRI" triggers from 10:15 a.m. Monday to Friday.
"0 15 10 15 *?" Triggered at 10:15 a.m. on the 15th of each month.
"0 1510 L*?" Triggered at 10:15 a.m. on the last day of each month.
"0 1510?* 6L" is triggered at 10:15 a.m. on the last Friday of each month.
"0 1510?* 6L 2002-2005" triggered at 10:15 a.m. on the last Friday of each month from 2002 to 2005
Triggered at 10:15 a.m. on the third Friday of the month
Some subexpressions can contain ranges or lists
For example, sub-expressions (days (weeks) can be "MON-FRI", "MON, WED, FRI", "MON-WED,SAT".
The "*" character represents all possible values
Therefore, "*" means every month in the sub-expression (month), and "*" means every day of the week in the sub-expression (day (week).
The "/" character is used to specify the increment of the value
For example, "0/15" in a subexpression (minute) means that it starts at minute 0, every 15 minutes.
"3/20" in a subexpression (minute) means every 20 minutes (it has the same meaning as "3, 23, 43") starting at the third minute.
"?" Characters are used only for day (month) and day (week) sub-expressions, indicating no specified value.
When one of the two sub-expressions has been assigned a value, in order to avoid conflict, the value of the other sub-expression needs to be set to "?"
The "L" character is used only for days (months) and days (weeks), which is the abbreviation of the word "last".
But it has different meanings in two sub-expressions.
In the sky (month) subexpression, "L" means the last day of a month.
In the day (week) self-expression, "L" means the last day of a week, that is, SAT.
If there is specific content before "L", it has other meanings.
For example, "6L" means the penultimate sixth day of the month, and "FRIL" means the last Friday of the month.
Note: When using the "L" parameter, do not specify a list or range, as this can cause problems.
field | Allowable value | Allowed special characters | ||
---|---|---|---|---|
Second |
0-59 |
, - * / |
||
Points |
0-59 |
, - * / |
||
Hour |
0-23 |
, - * / |
||
Date |
1-31 |
, - * ? / L W C |
||
Month |
1-12 or JAN-DEC |
, - * / |
||
Week |
1-7 or SUN-SAT |
, - * ? / L C # |
||
Year (optional) |
Leave empty, 1970-2099 |
, - * / |