java进阶-线程池 - D - 1 - ScheduledExecutorService类

从字面上理解-有计划的执行服务  ====> ”普通fa“ 翻译 -->定时执行任务

这里涉及到的类主要就是  ScheduledExecutorService接口,以及实现该接口的  ScheduledThreadPoolExecutor类

scheduledThreadPoolExecutor类还继承了ThreadPoolExecutor类

第一期

解析一下  scheduledThreadPoolExecutor 相比 ThreadPoolExecutor 特有的几个方法,理解这几个方法,不挖内部实现的源码

接口给了我们4个方法

前2个

(1)schedule(Runnable ,long delay,TimeUnit)  /     schedule(Callable,long delay,TimeUnit)

主要是针对不同的线程创建接口

 

(2)scheduleAtFixedRate( Runnable  ,  long initialDelay ,  long period ,  TimeUnit ) 

1.第一次任务延迟 initialDelay  加载

每次可以执行任务的时间节点 间隔 period

时间单位是 TimeUnit

结合例子 No picture 不BB

传入三个任务 A 10秒  B 20秒  C 15秒   ,initialDelay 设置为0 ,period时间设置为 15 TimeUnit设置为 秒

java进阶-线程池 - D - 1 - ScheduledExecutorService类

(3)scheduleWithFixedDelay(Runnable  , long initialDelay  ,  long delay  , TimeUnit)

2.第一次任务延迟 initialDelay 加载

每次任务执行结束要间隔 delay 

时间单位是 TimeUnit

结合例子 No picture 不BB

传入三个任务 A 10秒  B 20秒  C 15秒  ,initialDelay 设置为0 ,period时间设置为 15 TimeUnit设置为 秒

java进阶-线程池 - D - 1 - ScheduledExecutorService类

,大概就是这么些东西了,定时线程池还是比较常用的,需要在深入理解内部工作原理

相关文章:

  • 2021-11-19
  • 2021-10-03
  • 2021-11-25
  • 2021-07-29
  • 2022-12-23
  • 2021-08-04
  • 2021-06-04
  • 2021-06-20
猜你喜欢
  • 2021-12-14
  • 2022-02-27
  • 2021-09-17
  • 2021-09-24
  • 2022-12-23
  • 2021-08-12
  • 2021-11-17
相关资源
相似解决方案