官方文档

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. 微信小程序中的事件

    事件 说明 bindtap bindload 当图片载入完毕时触发,event.detail = {height, width} bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒 ...

  2. Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing

    链接: https://codeforces.com/contest/1278/problem/A 题意: Polycarp has built his own web service. Being ...

  3. java 读写Parquet格式的数据 Parquet example

    import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOExce ...

  4. LeetCode 885. Spiral Matrix III

    原题链接在这里:https://leetcode.com/problems/spiral-matrix-iii/ 题目: On a 2 dimensional grid with R rows and ...

  5. zzulioj - 2618: ACM-ICPC亚洲区域赛ZZULI站

    题目链接; http://acm.zzuli.edu.cn/problem.php?id=2618 题目描述 玩了这么多游戏,V决定还是去做几道ACM题练练手,于是翻到了一道201X年ACM/ICPC ...

  6. 将HashMap转换为List

    背景 ​ SpringBoot中,使用@RquestBody注解 hashMap 接收多个参数的json字符串数据,包括一个数组和一个int值.数组中为一个个的对象组成. 问题 ​ 使用 map.ge ...

  7. ESA2GJK1DH1K基础篇: 阿里云物联网平台: 测试MQTT连接阿里云物联网平台

    前言 这节看一下在阿里云上实现MQTT通信是个怎样的流程 看了很多网上的教程,感觉讲的迷迷糊糊.... 其实感觉他们是对MQTT不够透彻,所以写的文章就是个比着葫芦画瓢的感觉 在我面前这东西就是玩具. ...

  8. SQL 变形

    需求:共有协议X份,已签XX份,待签X份 sql: select count(1) 总记录数, sum(case when XY_STATUS='1' then 1 else 0 end)待签, su ...

  9. K8s预选策略和优选函数简介

    调度器选择策略: 预选策略(Predicate) 1. 根据运行Pod的资源限制来排除不符合要求的Node 2. 根据运行Pod时,是否要求共享宿主机的网络名称空间来判断,如: 某Pod启动要共享宿主 ...

  10. TensorFlow实现文本情感分析详解

    http://c.biancheng.net/view/1938.html 前面我们介绍了如何将卷积网络应用于图像.本节将把相似的想法应用于文本. 文本和图像有什么共同之处?乍一看很少.但是,如果将句 ...