ThreadPoolExecutor与ScheduledThreadPoolExecutor

本文最后更新于:2017年4月7日 凌晨

之前有开源过一个Jacksgong/ThreadDebugger的开源库,主要用于监控线程变化以及封装的各类的线程池
很早就想将ThreadPoolExecutorScheduledThreadPoolExecutor的理解整理下,但是由于这块逻辑用文字表达起来相对不好理解,因此还是决定用图片来表达。

ThreadPoolExecutor

ScheduledThreadPoolExecutor

需要注意

  • scheduleAtFixedRate: 无论运行任务用的多久,还是指定固定的时间执行,如任务在initDelay, initDelay + period, initDelay + period * 2会被执行
  • scheduleWithFixedDelay: 指定固定的间隔执行,如每次都是在上次执行后间隔delay以后执行

当然,如果是简单的单线程复用,可以考虑直接使用Handler,这块可以参见Android Handler Looper机制这篇文章。



ThreadPoolExecutor与ScheduledThreadPoolExecutor
https://blog.dreamtobe.cn/thread-pool/
作者
Jacksgong
发布于
2017年4月4日
更新于
2017年4月7日
许可协议