先上一段代码

package com.xxl.job.executor.utils;import groovy.util.logging.Slf4j;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;@Component
public class OrderService {/*** bean初始化的时候,启动一个线程* 每10MS,把队列里的请求批量请求*/@PostConstructpublic void init(){ScheduledExecutorService scheduledExecutorService=Executors.newScheduledThreadPool(1);scheduledExecutorService.scheduleAtFixedRate(new Runnable() {@Overridepublic void run() {System.out.println("AAA");}},0,5, TimeUnit.SECONDS);//间隔五秒}@PreDestroypublic void destroy(){System.out.println("注销!");}}

1.scheduleAtFixedRate是以上一次任务的开始时间为间隔的,并且当任务执行时间大于设置的间隔时间时,真正间隔的时间由任务执行时间为准

2.scheduleWithFixedDelay是以上一次任务的结束时间为间隔的

3.异常如果不捕获则会停止调度

scheduleAtFixedRate和scheduleWithFixedDelay方法相关推荐

  1. ScheduledExecutorService中scheduleAtFixedRate方法与scheduleWithFixedDelay方法的区别

    ScheduledExecutorService中scheduleAtFixedRate方法与scheduleWithFixedDelay方法的区别 ScheduledThreadPoolExecut ...

  2. 详解scheduleAtFixedRate与scheduleWithFixedDelay原理

    前言 前几天,肥佬分享了一篇关于定时器的文章你真的会使用定时器吗?,从使用角度为我们详细地说明了定时器的用法,包括 fixedDelay.fixedRate,为什么会有这样的区别呢?下面我们从源码角度 ...

  3. scheduleAtFixedRate和scheduleWithFixedDelay 区别

    https://www.jianshu.com/p/2900b4fd3bdd Executors提供的线程池ScheduledExecutorService中有两个方法,scheduleAtFixed ...

  4. newScheduledThreadPool : scheduleAtFixedRate 与 scheduleWithFixedDelay 详解

    一.引言 newScheduledThreadPool 周期性线程池提供了周期执行任务的方法 scheduleAtFixedRate 与 scheduleWithFixedDelay,两者比较容易混淆 ...

  5. ScheduledExecutorService的简单使用、scheduleAtFixedRate和scheduleWithFixedDelay区别

    ScheduledExecutorService的简单使用.scheduleAtFixedRate和scheduleWithFixedDelay区别 ScheduledExecutorService ...

  6. 写段代码理解 scheduleAtFixedRate和scheduleWithFixedDelay

    ① 如果任务在周期内正常结束掉的话scheduleAtFixedRate和scheduleWithFixedDelay没有差别 public void start() {ScheduledExecut ...

  7. Java定时线程实现:scheduleAtFixedRate 和 scheduleWithFixedDelay 的差别

    Java实现定时任务,一般都是用一个线程,设置个时间,让他定时执行,注意力一般都是集中在这个线程的实现,很少考虑到具体定时执行线程的这个过程.scheduleAtFixedRate 和 schedul ...

  8. 彻底理解scheduleAtFixedRate 与 scheduleWithFixedDelay

    scheduleAtFixedRate 以上一个任务***开始的时间***计时,period时间过去后,检测上一个任务是否执行完毕,如果上一个任务执行完毕,则当前任务立即执行,如果上一个任务没有执行完 ...

  9. scheduleAtFixedRate 与 scheduleWithFixedDelay 的区别

    总结: scheduleAtFixedRate ,是以上一个任务开始的时间计时,period时间过去后,检测上一个任务是否执行完毕,如果上一个任务执行完毕,则当前任务立即执行,如果上一个任务没有执行完 ...

最新文章

  1. pythonclass全局变量_Python-多处理全局变量更新未返回给父级
  2. 为什么百度首页的HTML源代码最后一行要多一行?浪费空间呀!
  3. Oracle APEX 系列文章7:Oracle APEX 18.1 新特性
  4. python matplotlib绘图 axes和pyplot用法的区别是什么?子图subplot
  5. Spring Boot修改内置Tomcat端口号
  6. RxSwift之UI控件UISlider与UIStepper扩展的使用
  7. jQuery学习笔记(四)
  8. vue项目中使用sass的方法
  9. 关于 Kubernetes中集群统一日志管理方案(Elasticsearch+Filebeat+Kibana+Metricbeat)搭建的一些笔记
  10. 拖动滑块验证 php,基于JS组件实现拖动滑块验证功能
  11. 如何查看浏览器cookie?附2个方法
  12. flex布局中的align-content属性
  13. java 静态抽象类_java--抽象类实例(包含静态内部抽象类)
  14. 盐于律己,甜以待人(*╹▽╹*)
  15. C#+ItextSharp 查看pdf文件页面尺寸
  16. 山水印|竹林野茶:在这个临近八月中秋的九月,再喝桂花香茶
  17. 【文献翻译】信息安全管理自动化的可能性 - Automation possibilities in information security management
  18. 查询快递物流信息在哪里查
  19. DEAP:使用生理信号进行情绪分析的数据库(三、实验分析与结论)
  20. S-Video连接电视,其他程序一切正常,就是不能看视屏?

热门文章

  1. 重磅!银保监会开展侵害个人信息权益乱象专项整治工作
  2. Python openjudge练习:015:计算邮资
  3. R语言使用rnorm函数生成正太分布数据、使用plot函数可视化折线图、使用points函数指定数据点的颜色、使用lines函数指定线条的颜色
  4. jQuery-UI组件Effects
  5. apache mina 与 SEDA
  6. oracle服务不见了怎么解决
  7. linux grep工作常用
  8. 对于Spring中事务的readonly属性理解
  9. 大环境不好的情况下 我们改如何做
  10. 【C++ Socket编程】(二)阻塞+多线程