首页 > 其他分享 >Spring Boot 定时任务 @Scheduled(cron="[秒] [分] [小时] [日] [月] [周] [年]")

Spring Boot 定时任务 @Scheduled(cron="[秒] [分] [小时] [日] [月] [周] [年]")

时间:2023-01-01 17:23:38浏览次数:61  
标签:Scheduled 字符 16 Spring Boot 整数 cron https

@Scheduled(cron="[秒] [分] [小时] [日] [月] [周] [年]")

说明:

多个并列的时间以英文逗号“,”隔开。

比如:

@Scheduled(cron = "0 53,55 16 1 * *")

上面意思是:1号的下午16:53 ,16:55执行二次。

 

@Scheduled(cron = "0/10 * * * * ?")

上面意思是:每隔10秒运行一次。

 

Seconds: 可出现", - * /"四个字符,有效范围为0-59的整数 
Minutes: 可出现", - * /"四个字符,有效范围为0-59的整数 
Hours: 可出现", - * /"四个字符,有效范围为0-23的整数 
DayofMonth :可出现", - * / ? L W C"八个字符,有效范围为0-31的整数 
Month: 可出现", - * /"四个字符,有效范围为1-12的整数或JAN-DEc 
DayofWeek: 可出现", - * / ? L C #"四个字符,有效范围为1-7的整数或SUN-SAT两个范围。1表示星期天,2表示星期一, 依次类推 
Year: 可出现", - * /"四个字符,有效范围为1970-2099年

1)启动类中加入:

@EnableScheduling

比如:

@EnableScheduling

public class XXXApplication extends SpringBootServletInitializer {

   ……

}

2)业务类中

@Scheduled(cron = "0 53,55 16 1 * *")

@Override

public int updateScheduling() {

System.out.println("update ");

return 0;

}

 

参考:

https://www.bloghome.com.cn/post/scheduled-cronbiao-da-shi.html

https://blog.csdn.net/nbzhaomao/article/details/125730315

https://blog.csdn.net/qq78442761/article/details/109128687

https://www.cnblogs.com/shenStudy/p/15577733.html

标签:Scheduled,字符,16,Spring,Boot,整数,cron,https
From: https://www.cnblogs.com/jiduoduo/p/17018292.html

相关文章