当前位置:网站首页>@Scheduled注解详解
@Scheduled注解详解
2022-08-01 23:41:00 【drhrht】
文章目录
1.注解源码
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(Schedules.class)
public @interface Scheduled {
String cron() default "";
String zone() default "";
long fixedDelay() default -1;
String fixedDelayString() default "";
long fixedRate() default -1;
String fixedRateString() default "";
long initialDelay() default -1;
String initialDelayString() default "";
}
2.注解参数
参数
说明
示例
cron
任务执行的cron表达式
0/2 * * * *
zone
cron表达时解析使用的时区,默认为服务器的本地时区。
使用java.util.TimeZone#getTimeZone(String)方法解析
GMT-8:00
fixedRate
固定速率上一次任务执行开始到下一次执行开始的间隔时间固定,单位为ms。若在调度任务执行时,上一次任务还未执行完毕,会加入worker队列,等待上一次执行完成后,马上执行下一次任务
1000
fixedRateString
与fixedRate一致,只是间隔时间使用java.time.Duration#parse解析
1000或PT1S
fixedDelay
固定延迟上一次任务执行结束到下一次执行开始的间隔时间固定,单位为ms。
1000
fixedDelayString
与fixedDelay一致,只是间隔时间使用java.time.Duration#parse解析
1000或PT1S
initialDelay
首次延迟多长时间后执行,单位ms。
之后按照fixedRate、fixedRateString、fixedDelay、fixedDelayString指定的规则执行,需要指定其中一个规则。
注意:不能和cron一起使用
1000
initialDelayString
与initialDelay 一致,只是间隔时间使用java.time.Duration#parse解析
1000或PT1S
3.示例
cron
@Scheduled(cron = "0/2 * * * * ?")
从0秒开始,每隔两秒执行一次。
zone
@Scheduled(cron = "0/2 * * * * ?", zone = "GMT-8:00")
从0秒开始,每隔两秒执行一次。
指定时间使用的时区为东八区。
fixedRate
@Scheduled(fixedRate = 1000)
1秒执行一次,上次执行开始后过1秒执行下一次。若到了1秒后但上次执行还未完成,会加入worker队列,等待上一次执行完成后,马上执行下一次。
fixedRateString
@Scheduled(fixedDelayString = "1000")
@Scheduled(fixedDelayString = "PT1S")
都表示1秒执行一次,上次执行开始后过1秒执行下一次。若到了1秒后但上次执行还未完成,会加入worker队列,等待上一次执行完成后,马上执行下一次。
fixedDelay
@Scheduled(fixedDelay = 1000)
1秒执行一次,上次执行完成后过1秒继续执行下一次。
fixedDelayString
@Scheduled(fixedDelayString = "1000")
@Scheduled(fixedDelayString = "PT1S")
都表示1秒执行一次,上次执行完成后过1秒继续执行下一次。
initialDelay
@Scheduled(initialDelay = 5000, fixedRate = 2000)
首次5秒后执行,后续每隔2秒执行一次(遵循fixedRate 规则)
@Scheduled(initialDelay = 5000, fixedDelay = 2000)
首次5秒后执行,后续每隔2秒执行一次(遵循fixedDelay 规则)
注意:initialDelay、initialDelayString都不能和cron一起使用
initialDelayString
@Scheduled(initialDelayString = "5000", fixedRate = 2000)
首次5秒后执行,后续每隔2秒执行一次(遵循fixedRate 规则)
@Scheduled(initialDelayString = "5000", fixedDelay = 2000)
首次5秒后执行,后续每隔2秒执行一次(遵循fixedDelay 规则)
注意:initialDelay、initialDelayString都不能和cron一起使用
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- DRF generating serialization class code
- Making a Simple 3D Renderer
- 软件测试之移动APP安全测试简析,北京第三方软件检测机构分享
- 论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
- drf生成序列化类代码
- 中职网络安全竞赛B7比赛部署流程
- 部门项目源码分享
- Calculate the distance between two points
- Additional Features for Scripting
- 6133. 分组的最大数量
猜你喜欢

Sql之各种Join

分享一份接口测试项目(非常值得练手)

简单3D渲染器的制作

sys_kill系统调用
![[Camp Experience Post] 2022 Cybersecurity Summer Camp](/img/1e/716bafc679dc67d3d54bcc21a3b670.png)
[Camp Experience Post] 2022 Cybersecurity Summer Camp

sys_kill system call

Quartus 使用 tcl 文件快速配置管脚
![[LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph](/img/63/16de443caf28644d79dc6e6889e5dd.png)
[LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph

深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练

PDF转Word有那么难吗?做一个文件转换器,都解决了
随机推荐
Is TCP reliable?Why?
UI自动化测试框架搭建-标记性能较差用例
毕业作业
Avoid , ,
, and tagsPDF转Word有那么难吗?做一个文件转换器,都解决了
FAST-LIO2代码解析(二)
cdh6打开oozieWeb页面,Oozie web console is disabled.
加载字体时避免隐藏文本
perspectiveTransform warpPerspective getPerspectiveTransform findHomography
Oracle database is set to read-only and read-write
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
检查点是否在矩形内
Loading configuration of Nacos configuration center
Secondary Vocational Network Security Competition B7 Competition Deployment Process
技术分享 | 接口测试中如何使用Json 来进行数据交互 ?
计算两点之间的中点
Share an interface test project (very worth practicing)
qt-faststart installation and use
深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
请问什么是 CICD