官方文档

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. boost与MFC的冲突(new)

    在MFC对话框程序中用boost::signals2时出现了问题, 由于MFC为了方便调试,在debug下重新定义了new #ifdef _DEBUG#define new DEBUG_NEW#end ...

  2. 云数据库 Redis 版,知识点

    资料 网址 什么是云数据库Redis版 https://help.aliyun.com/document_detail/26342.html?spm=a2c4g.11174283.6.542.6b11 ...

  3. 禁用wordpress模板默认样式

    我们知道wordpress主题比如twentytwenty都会有样式,如果不想使用它们的默认样式怎么处理呢?其实很简单,随ytkah一起来看看吧.进入2020主题的function.php文件,里面有 ...

  4. Maven 中 dependencyManagement 标签使用

    1.在Maven中dependencyManagement的作用其实相当于一个对所依赖jar包进行版本管理的管理器. 2.pom.xml文件中,jar的版本判断的两种途径 1:如果dependenci ...

  5. JRebel激活教程

    JRebel的官方地址(https://zeroturnaround.com/software/jrebel),土豪可以自行去官网购买. 安装 打开IDEA-->setting-->plu ...

  6. JDOJ 2982: 最大连续子段和问题

    洛谷 P1115 最大子段和 洛谷传送门 JDOJ 2982: 最大连续子段和问题 JDOJ传送门 题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入格式 第一行是一个正整数NN, ...

  7. USACO Cow Frisbee Team

    洛谷 P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team 洛谷传送门 JDOJ 2632: USACO 2009 Mar Silver 2.Cow Frisbee Team ...

  8. Candy Treasure Box

    This is an interesting puzzle game. In the game, you need to use your brain, think carefully, operat ...

  9. Mybatis集成ehcache

    Mybatis集成ehcache 1.为什么需要缓存 拉高程序的性能 2. 什么样的数据需要缓存 很少被修改或根本不改的数据 业务场景比如:耗时较高的统计分析sql.电话账单查询sql等 3. ehc ...

  10. 【原】无脑操作:Markdown可以这样玩

    一.背景: Markdown是一种纯文本格式的标记语言.通过简单的标记语法,可以使普通文本内容具有一定的格式.因为语法简单明了.功能又比纯文本强大,所以很适合作为开发人员的书写工具.Markdown的 ...