在Spring Boot中使用@Scheduled实现定时任务
来源:互联网 发布:淘宝为什么不能改名字 编辑:程序博客网 时间:2024/06/06 05:33
之前没有使用spring Boot的Java风格配置的时候,用XML配置过@Scheduled定时任务,现在都习惯使用Java风格配置了,在此简单记录
一下Spring Boot的@Scheduled定时任务的实现过程。
1. 添加@EnableScheduling
注解到入口类声明上面,如下所示:
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
2. 将@Scheduled
添加到不带参数的方法上,如下所示:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
其中@Scheduled
注解后面括号里面可以指定各种参数,在上面代码里面的fixedRate = 6000
意思是下面的任务每隔6000毫秒,即每隔6秒执行一次。
下面简单提一下cron
表达式,举个例子:
- 1
- 1
cron
表达式中各时间元素使用空格进行分割,分别表示如下含义:
按顺序依次为
秒(0~59)
分钟(0~59)
小时(0~23)
天(月)(0~31,但是你需要考虑你月的天数)
月(0~11)
天(星期)(1~7 1=SUN 或 SUN,MON,TUE,WED,THU,FRI,SAT)
7.年份(1970-2099)
阅读全文
0 0
- 在Spring Boot中使用@Scheduled实现定时任务
- 在Spring Boot中使用@Scheduled实现定时任务
- 在Spring Boot中使用@Scheduled实现定时任务
- 在Spring Boot中使用@Scheduled实现定时任务
- 在Spring Boot中使用@Scheduled实现定时任务
- Spring Boot中使用@Scheduled创建定时任务
- Spring Boot中使用@Scheduled创建定时任务
- Spring Boot中使用@Scheduled创建定时任务
- spring-boot 使用@Scheduled 开启定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- Winsock编程实例
- unity 贪吃蛇作战—2
- Python 字典(dict) 操作基础
- 顺序表的实现,插入,删除,定位,合并,打印
- Activity启动流程分析
- 在Spring Boot中使用@Scheduled实现定时任务
- 关于js中几种遍历方法性能的测试
- leetcode 318. Maximum Product of Word Lengths
- Redhat6.5二进制安装mysql5.7.9(详细)
- bootstrap获取隐藏列值
- Count on a tree SPOJ
- Activity 4种启动模式launchMode
- Linux实验室 apt命令应用全解析
- jmeter中文版新手入门教程