官方文档

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. 负载均衡环境:nginx + 2tomcat

    部署两个服务 安装两个tomcat,tomcat安装,参考:https://www.cnblogs.com/uncleyong/p/10742650.html 两个tomcat的端口要不一样(shut ...

  2. 什么是amp?amp有什么用处?

    AMP是移动页面加速器Accelerated Mobile Pages的简称,是Google带领开发的开源项目,目的是为提升移动设备对网站的访问速度.它的核心称作AMP HTML,是一种新型的HTML ...

  3. The Best Blockchain Open Source Projects

    https://101blockchains.com/blockchain-open-source/ Blockchain has been the buzzword of the year for ...

  4. java http get和post请求

    1.http工具类 package com.funshion.common.utils; import java.net.URI;import java.net.URL; import org.apa ...

  5. Generating YouTube-like IDs in Postgres using PL/V8 and Hashids

    转自:https://blog.abevoelker.com/2017-01-03/generating-youtube-like-ids-in-postgres-using-plv8-and-has ...

  6. 云服务器使用: 为域名申请SSl证书

    注:咱们平时访问网站 有的是http  有的是 https https就是说使用了SSL访问 然后就是等着..... 假设可以了 然后就会有各个软件使用的证书,然后根据自己安装的软件下载证书

  7. NOIP2013-2014提高组题目浅析

    1.前言 迎接NOIP的到来...在这段闲暇时间,决定刷刷水题.这里只是作非常简单的一些总结. 2.NOIP2014 <1> 生活大爆炸之石头剪刀布(模拟) 这是一道考你会不会编程的题目. ...

  8. priority_queue(优先队列)使用方法

    priority_queue默认是一个大根堆: 并且出队方式与普通队列queue的front不一样,是top . 如果想用小根堆,可以修改定义时的参数: priority_queue<int,v ...

  9. ISE 14.7安装教程最新版(Win10安装)

    一.下载 第一步下载首先自己下载好四个压缩包,把第一个解压,其余的三个不用解压,然后去第一个解压后的文件夹打开启动程序. 第二步是点击启动程序后会有以下界面 next到下一个界面,这个时候需要把之前没 ...

  10. 不刷新网页修改url链接:history.pushState()和history.replaceState()新增、修改历史记录用法介绍

    最近遇到了在不刷新页面的情况下修改浏览器url链接的需求,考虑到可以通过history.pushState()解决.现在将我理解的一些内容分享一下,不对的地方欢迎大家指出. 在使用方法前首先需要了解它 ...