原文链接

1 格局

{秒数} {分钟} {小时} {日期} {月份} {星期} {年份(可为空)}

2 用法

  • "30 ? " 每半分钟触发工作
  • "30 10 * ? " 每小时的10分30秒触发工作
  • "30 10 1 ? " 每天1点10分30秒触发工作
  • "30 10 1 20 * ? " 每月20号1点10分30秒触发工作
  • "30 10 1 20 10 ? *" 每年10月20号1点10分30秒触发工作
  • "0 0/3 * ? " 每小时的第0分0秒开始,每三分钟触发一次
  • "0 0-5 14 ?" 在每天下午2点到下午2:05期间的每1分钟触发

3 实例

@RestController@EnableSchedulingpublic class MyController {        @Scheduled(cron = "1/10 * * * * ? ")  //10s一次        public void learn(){                System.out.println("hello world");        }}

4 在线生成

在线生成 cron 语句的网站:

https://www.bejson.com/othert...

 
 

学习更多编程常识,请关注我的公众号:

代码的路