ThreadPoolExecutor原理

ThreadPoolExecutor 源码

The main pool control state

属性 ctl 用来表示表示他内部的两个状态:工作线程数(workerCount),运行状态(runState):

1
2
3
4
5
6
7
/**
* The main pool control state, ctl, is an atomic integer packing
* two conceptual fields
* workerCount, indicating the effective number of threads
* runState, indicating whether running, shutting down etc
*/
private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0));
Read more