需要的包
org.springframework spring-context-support ${spring.version}
org.quartz-scheduler quartz 2.2.1 org.quartz-scheduler quartz-jobs 2.2.1
spring中配置bean
0 */2 * * * ?
Cron Expressions 轮询表达式(我翻译的,个人理解)
Cron-Expressions are used to configure instances of CronTrigger. Cron-Expressions are strings that are actually made up of seven sub-expressions, that describe individual details of the schedule. These sub-expression are separated with white-space, and represent
- Seconds
- Minutes
- Hours
- Day-of-Month
- Month
- Day-of-Week
- Year (optional field)
轮询表达式用来初始化调度器,轮询表达式是一个由七个空格分开的子表达式组成的字符串。它描述了调度详情。这些子表达式由空格分开,分表表示 “秒 分 小时 每个月份中哪一天 月份 每周的哪一天 年(可选项)”
Example Cron Expressions 轮询表达式举例
CronTrigger Example 1 - an expression to create a trigger that simply fires every 5 minutes
“0 0/5 * * * ?” 每5分钟执行一次
CronTrigger Example 2 - an expression to create a trigger that fires every 5 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:05:10 am, etc.).
“10 0/5 * * * ?” 每五分钟的第十秒执行
CronTrigger Example 3 - an expression to create a trigger that fires at 10:30, 11:30, 12:30, and 13:30, on every Wednesday and Friday.
“0 30 10-13 ? * WED,FRI” 每天10点到13点种,每半个小时执行一次。
CronTrigger Example 4 - an expression to create a trigger that fires every half hour between the hours of 8 am and 10 am on the 5th and 20th of every month. Note that the trigger will NOT fire at 10:00 am, just at 8:00, 8:30, 9:00 and 9:30
“0 0/30 8-9 5,20 * ?” 每个月的第5号和第20号,每天8点到9点,每半个小时执行一次【8:00,8:30,9:00,9:30】。(比较绕,静下心来好好看)