The second trigger in the task scheduler to be introduced is CronTrigger. Compared with SimpleTrigger, CronTrigger is more flexible and more practical for complex business needs. Before using CronTrigger, you must first introduce the Cron expression. Here, the content of Cron expressions is introduced on the Internet. The theoretical content is roughly the same.
The content of the Cron expression is as follows:
The special symbols in the expression indicate:
"?" Character: indicates an uncertain value, for example, 0 0 0 **?)
"," Character: specifies several values
-Character: Specifies the range of a value.
"/" Character: Specifies the increase range of a value. N/m indicates that m is increased each time starting from n.
"L" character: Used in the day to represent the last day of the month, used in the week to represent the last day of the month X
"W" character: Specifies the business day closest to the given date (Monday to Friday)
"#" Character: indicates the week X of the month. 5 #2 indicates the first Thursday of the month
AM on every Monday, Thursday, and Thursday |
|
AM on the 10th of every month |
|
AM on the last day of each month |
|
AM on the last Friday of every month |
|
At AM on the last Friday of 2014,201, 2016, and 2017 |
|
AM on the third Friday of every month |
|
Every five days from the first day of every month (noon) |
|
Every November 11 AM |
|
And every Wednesday in March |
|
QuartzCronTiggerJob execute (JobExecutionContext jobContext) "This Is A cronTrigger test class"
(2) Task Scheduler
Scheduler scheduler = JobDetail jobDetail ="cronTriggerDetail", "cronTriggerDetailGrounp" JobDataMap jobDataMap ="name", "cronTriggerMap""group", "cronTriggerGrounp" CronTrigger cronTrigger = newTrigger(). withIdentity("cronTrigger", "cronTrigger""0 48 14 * * ?" build();
The above is the simple use of CronTrigger of Version 2.0. You can schedule tasks based on specific services.