CronTriggers are often more useful than SimpleTrigger, when you need jobs executed based on calendar-like schedules rather than simple intervals specified by SimpleTrigger.
CronTrigger allows you to specify calendar-based schedules such as:
Like SimpleTrigger, CronTrigger has a startTime (when the schedule is in effect) and an optional endTime (when the schedule should cease).
A cron expression is a string consisting of 7 sub-expressions that describe individual details of the schedule:
Seconds Minutes Hours Day-of-Month Month Day-of-Week Year (Year field optional)
For example: "0 0 12 ? * WED" means execute every Wednesday at 12:00 PM
| Field | Allowed Values | Special Characters |
|---|---|---|
| Seconds | 0-59 | , - * / |
| Minutes | 0-59 | , - * / |
| Hours | 0-23 | , - * / |
| Day-of-Month | 1-31 | , - * ? / L W |
| Month | 0-11 或 JAN-DEC | , - * / |
| Day-of-Week | 1-7 (1=星期日) 或 SUN-SAT | , - * ? / L # |
| Year (optional) | 1970-2099 | , - * / |
| Character | Meaning | Example |
|---|---|---|
| * | All values | "*" in minutes field means every minute |
| ? | No specific value (only used in Day-of-Month and Day-of-Week fields) | "?" in Day-of-Month field means ignore this field |
| - | Range | "10-12" in hours field means 10, 11, and 12 o'clock |
| , | List multiple values | "MON,WED,FRI" in Day-of-Week field means Monday, Wednesday, Friday |
| / | Increments | "0/15" in seconds field means every 15 seconds starting from 0 seconds |
| L | Last day (of month or week) | "L" in Day-of-Month field means the last day of the month |
| W | Nearest weekday | "15W" in Day-of-Month field means the nearest weekday to the 15th of the month |
| # | Nth weekday of the month | "6#3" in Day-of-Week field means the third Friday of every month |