在Spring Boot中使用@Scheduled实现定时任务
来源:互联网 发布:长虹社区软件下载 编辑:程序博客网 时间:2024/06/13 06:35
在Spring Boot中使用@Scheduled实现定时任务
之前没有使用Spring Boot的Java风格配置的时候,用XML配置过@Scheduled定时任务,现在都习惯使用Java风格配置了,在此简单记录
一下Spring Boot的@Scheduled定时任务的实现过程。
1. 添加@EnableScheduling
注解到入口类声明上面,如下所示:
- 1
- 2
- 3
- 4
- 5
2. 将@Scheduled
添加到不带参数的方法上,如下所示:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
其中@Scheduled
注解后面括号里面可以指定各种参数,在上面代码里面的fixedRate = 6000
意思是下面的任务每隔6000毫秒,即每隔6秒执行一次。
下面简单提一下cron
表达式,举个例子:
- 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实现定时任务
- Java类和对象的理解
- php常用的加速缓存的扩展
- GO语言入门学习网站
- 什么是JSP技术?
- 微信支付证书问题(C#)
- 在Spring Boot中使用@Scheduled实现定时任务
- 鼠标上移、移走、点击事件
- CCF认证201503-3 节日
- C语言中的回掉和递归
- C# WebApi Fiddler调试post接口
- 第二章 HelloWord安卓工程介绍
- VB通过webbrowser获取httponly的cookie
- Android逆向系列之动态调试1–入门篇
- SnapHelperExample