Scheduling Tasks
官方文档
https://spring.io/guides/gs/scheduling-tasks/
官方文档详细介绍了@Scheduled中fixedRate,fixedDelay,cron的用法

fixedRate代表调用频率,单位为ms,如果调用频率设为5000ms,那么当你第一次调用占用2秒时等待3秒会第二次调用,当你第二次调用占用5秒时结束会立马第三次调用。
fixedDelay代表间隔时间,单位为ms,即每次调用完成时间和下次调用都相隔5000ms。
cron表达式,看官网文档
fixedDelay验证
情况一,程序执行时间小于延迟时间
设置延迟5秒时,执行时间为3秒
@Scheduled(fixedDelay=5000)
public void execute() throws InterruptedException {
System.out.println("调用时间"+CommonTool.getNowDateStr());
Thread.sleep(3000);
}

发现两次开始调用时间为8秒刚好为执行时间+等待时间
情况二,程序执行时间大于延迟时间
设置延迟5秒,并且方法调用时间为6秒时
@Scheduled(fixedDelay=5000)
public void execute() throws InterruptedException {
System.out.println("调用时间"+CommonTool.getNowDateStr());
Thread.sleep(6000);
}

发现间隙为11,也为执行时间+等待时间
fixedRate验证
情况一,程序执行时间小于延迟时间
设置延迟5秒时,执行时间为3秒

发现间隔时间即为5秒
情况二,程序执行时间大于延迟时间
设置延迟5秒,并且方法调用时间为6秒时

发现调用间隔为6秒,由此可见是单线程运行。
定时任务立即执行
@Scheduled(cron="* * * * * *")
Thread.sleep(24*3600*1000);
多个定时器同一时间触发只有一个执行
schedule是单线程的,阻塞的,所以千万不要长时间睡眠,会影响队列里其他schedule的执行。如果想多个schedule同时进行可以在xm里面配置线程池
Scheduling Tasks的更多相关文章
- 十三、springboot集成定时任务(Scheduling Tasks)
定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...
- 十五、springboot集成定时任务(Scheduling Tasks)(二)之(线程配置)
配置类: /** * 定时任务线程配置 * */ @Configuration public class SchedulerConfig implements SchedulingConfigurer ...
- SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot18-scheduling/ 本文出自方志朋的博客 ...
- Hypervisor, computer system, and virtual processor scheduling method
A hypervisor calculates the total number of processor cycles (the number of processor cycles of one ...
- Power aware dynamic scheduling in multiprocessor system employing voltage islands
Minimizing the overall power conservation in a symmetric multiprocessor system disposed in a system- ...
- SpringBoot中使用Scheduling执行定时任务
SpringBoot自带的 Schedule,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多 以下任务都是在单线程下执行的 第一步 创建SpringBoot项目 第二步 外汇 ...
- Android Weekly Notes Issue #234
Android Weekly Issue #234 December 4th, 2016 Android Weekly Issue #234 本期内容包括: ConstraintLayout的使用; ...
- Hadoop HDFS 用户指南
This document is a starting point for users working with Hadoop Distributed File System (HDFS) eithe ...
- Hadoop官方文档翻译——MapReduce Tutorial
MapReduce Tutorial(个人指导) Purpose(目的) Prerequisites(必备条件) Overview(综述) Inputs and Outputs(输入输出) MapRe ...
随机推荐
- Python input() 函数
Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获 ...
- Comet OJ 夏季欢乐赛 距离产生美
距离产生美 https://cometoj.com/contest/59/problem/B?problem_id=2680 题目描述 JWJU放暑假了,于是鸡尾酒就和女朋友璇璇一起出去玩.但是外面太 ...
- node开发遇到类似:Error: ENOENT: no such file or directory, scandir 'D:\work\taro-components- ....... _node-sass@4.12.0@node-sass\vendor
唯一的有参考价值的文章,https://www.cnblogs.com/milo-wjh/p/9175138.html 我可以负责任的说,以下的方法, npm rebuild node-sass 80 ...
- Native Clojure with GraalVM
转自:https://www.innoq.com/en/blog/native-clojure-and-graalvm/ GraalVM is a fascinating piece of techn ...
- 【CF573E】Bear and Bowling
[CF573E]Bear and Bowling 题面 洛谷 题解 首先有一个贪心的结论: 我们一次加入每个数,对于\(\forall i\),位置\(i\)的贡献为\(V_i = k_i\times ...
- 从零和使用mxnet实现softmax分类
1.softmax从零实现 from mxnet.gluon import data as gdata from sklearn import datasets from mxnet import n ...
- C语言博客作业04—数组
0.展示PTA总分(0----2) 展示3张关于"数组题目集"分数截图. 1.本章学习总结(2分) 1.1 学习内容总结 整理数组这章学习主要知识点,必须包含内容有: (1)数组查 ...
- NDCG、AUC介绍
https://blog.csdn.net/u014313009/article/details/38944687 SIGIR的一篇推荐算法论文中提到用NDCG和AUC作为比较效果的指标,之前没了解过 ...
- matplotlib折线图
绘制折线图:参考https://baijiahao.baidu.com/s?id=1608586625622704613 (3)近10年GDP变化的曲线图,及三次产业GDP变化的曲 ...
- 每日一问:谈谈 volatile 关键字
这是 wanAndroid 每日一问中的一道题,下面我们来尝试解答一下. 讲讲并发专题 volatile,synchronize,CAS,happens before, lost wake up 为了 ...