scheduleAtFixedRate和scheduleWithFixedDelay方法
先上一段代码
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方法相关推荐
- ScheduledExecutorService中scheduleAtFixedRate方法与scheduleWithFixedDelay方法的区别
ScheduledExecutorService中scheduleAtFixedRate方法与scheduleWithFixedDelay方法的区别 ScheduledThreadPoolExecut ...
- 详解scheduleAtFixedRate与scheduleWithFixedDelay原理
前言 前几天,肥佬分享了一篇关于定时器的文章你真的会使用定时器吗?,从使用角度为我们详细地说明了定时器的用法,包括 fixedDelay.fixedRate,为什么会有这样的区别呢?下面我们从源码角度 ...
- scheduleAtFixedRate和scheduleWithFixedDelay 区别
https://www.jianshu.com/p/2900b4fd3bdd Executors提供的线程池ScheduledExecutorService中有两个方法,scheduleAtFixed ...
- newScheduledThreadPool : scheduleAtFixedRate 与 scheduleWithFixedDelay 详解
一.引言 newScheduledThreadPool 周期性线程池提供了周期执行任务的方法 scheduleAtFixedRate 与 scheduleWithFixedDelay,两者比较容易混淆 ...
- ScheduledExecutorService的简单使用、scheduleAtFixedRate和scheduleWithFixedDelay区别
ScheduledExecutorService的简单使用.scheduleAtFixedRate和scheduleWithFixedDelay区别 ScheduledExecutorService ...
- 写段代码理解 scheduleAtFixedRate和scheduleWithFixedDelay
① 如果任务在周期内正常结束掉的话scheduleAtFixedRate和scheduleWithFixedDelay没有差别 public void start() {ScheduledExecut ...
- Java定时线程实现:scheduleAtFixedRate 和 scheduleWithFixedDelay 的差别
Java实现定时任务,一般都是用一个线程,设置个时间,让他定时执行,注意力一般都是集中在这个线程的实现,很少考虑到具体定时执行线程的这个过程.scheduleAtFixedRate 和 schedul ...
- 彻底理解scheduleAtFixedRate 与 scheduleWithFixedDelay
scheduleAtFixedRate 以上一个任务***开始的时间***计时,period时间过去后,检测上一个任务是否执行完毕,如果上一个任务执行完毕,则当前任务立即执行,如果上一个任务没有执行完 ...
- scheduleAtFixedRate 与 scheduleWithFixedDelay 的区别
总结: scheduleAtFixedRate ,是以上一个任务开始的时间计时,period时间过去后,检测上一个任务是否执行完毕,如果上一个任务执行完毕,则当前任务立即执行,如果上一个任务没有执行完 ...
最新文章
- pythonclass全局变量_Python-多处理全局变量更新未返回给父级
- 为什么百度首页的HTML源代码最后一行要多一行?浪费空间呀!
- Oracle APEX 系列文章7:Oracle APEX 18.1 新特性
- python matplotlib绘图 axes和pyplot用法的区别是什么?子图subplot
- Spring Boot修改内置Tomcat端口号
- RxSwift之UI控件UISlider与UIStepper扩展的使用
- jQuery学习笔记(四)
- vue项目中使用sass的方法
- 关于 Kubernetes中集群统一日志管理方案(Elasticsearch+Filebeat+Kibana+Metricbeat)搭建的一些笔记
- 拖动滑块验证 php,基于JS组件实现拖动滑块验证功能
- 如何查看浏览器cookie?附2个方法
- flex布局中的align-content属性
- java 静态抽象类_java--抽象类实例(包含静态内部抽象类)
- 盐于律己,甜以待人(*╹▽╹*)
- C#+ItextSharp 查看pdf文件页面尺寸
- 山水印|竹林野茶:在这个临近八月中秋的九月,再喝桂花香茶
- 【文献翻译】信息安全管理自动化的可能性 - Automation possibilities in information security management
- 查询快递物流信息在哪里查
- DEAP:使用生理信号进行情绪分析的数据库(三、实验分析与结论)
- S-Video连接电视,其他程序一切正常,就是不能看视屏?