官方文档

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的更多相关文章

  1. 十三、springboot集成定时任务(Scheduling Tasks)

    定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...

  2. 十五、springboot集成定时任务(Scheduling Tasks)(二)之(线程配置)

    配置类: /** * 定时任务线程配置 * */ @Configuration public class SchedulerConfig implements SchedulingConfigurer ...

  3. SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot18-scheduling/ 本文出自方志朋的博客 ...

  4. Hypervisor, computer system, and virtual processor scheduling method

    A hypervisor calculates the total number of processor cycles (the number of processor cycles of one ...

  5. Power aware dynamic scheduling in multiprocessor system employing voltage islands

    Minimizing the overall power conservation in a symmetric multiprocessor system disposed in a system- ...

  6. SpringBoot中使用Scheduling执行定时任务

    SpringBoot自带的 Schedule,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多 以下任务都是在单线程下执行的 第一步 创建SpringBoot项目 第二步 外汇 ...

  7. Android Weekly Notes Issue #234

    Android Weekly Issue #234 December 4th, 2016 Android Weekly Issue #234 本期内容包括: ConstraintLayout的使用; ...

  8. Hadoop HDFS 用户指南

    This document is a starting point for users working with Hadoop Distributed File System (HDFS) eithe ...

  9. Hadoop官方文档翻译——MapReduce Tutorial

    MapReduce Tutorial(个人指导) Purpose(目的) Prerequisites(必备条件) Overview(综述) Inputs and Outputs(输入输出) MapRe ...

随机推荐

  1. python的continue和pass的区别

    a = 'pythyon' i = 2 for element in a: if element == 'y': pass i = 3 else: print(element+str(i)) 结果: ...

  2. NOIP 2013 火柴排队

    洛谷 P1966 火柴排队 洛谷传送门 JDOJ 2227: [NOIP2013]火柴排队 D1 T2 JDOJ传送门 Description 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高 ...

  3. IEnumerable、IEnumerator接口(如何增加迭代器功能)

    IEnumerable.IEnumerator接口封装了迭代器功能,有了它,我们不需要将内部集合暴露出去,外界只需要访问我的迭代器接口方法即可遍历数据. 在C#中,使用foreach语句来遍历集合.f ...

  4. q1096

    一,看题 1,大概是每个点都来一次BFS标记下应该就可以. 2,你可以想想队列为啥pop()是l++; 3,还是字符你得注意下. 4,x,y,m,n,行列你得搞清楚. 5,这棋盘的破东西.. 6,额, ...

  5. 1. Spring Cloud Greenwich SR2 概览

    Spring Cloud provides tools for developers to quickly build some of the common patterns in distribut ...

  6. pytest--命令行常用参数

    前戏 在python中,大家听到最多的单元测试框架就是unittest和pytest了,而pytest有很多的功能,甩unittest几条街 我们在使用pytest时,要遵循pytest的命名规则: ...

  7. 洛谷[SHOI2002]滑雪题解

    什么破题啊 简直就是浪费我时间! 我每天还被我xf定目标了不知道嘛! 题目 朴素的搜索只能得90分 #include <cstdio> #include <iostream> ...

  8. nlp语义理解的一点儿看法

    nlp领域里,语义理解仍然是难题! 给你一篇文章或者一个句子,人们在理解这些句子时,头脑中会进行上下文的搜索和知识联想.通常情况下,人在理解语义时头脑中会搜寻与之相关的知识.知识图谱的创始人人为,构成 ...

  9. 每日一问:不一样的角度吐槽下 DataBinding

    我们项目采用的是 kotlin && DataBinding 处理的,可能你会疑问,既然用的是 kotlin,为啥没有用 kotlinx?新的页面当然是用的 kotlinx 啦,但我们 ...

  10. .NET 微服务 1. Docker 容器简介和选择

    容器特点 1. 容器可以将应用程序的依赖性和配置(抽象为 Mainfest 文件并部署)打包成一个容器镜像,可以让多次部署操作中的环境保持一致 2. 可以让IT人员很少或者不做修改就可以跨环境部署软件 ...