关于 ThreadPoolExecutor 成员变量

about ThreadPoolExecutor member variable

我英文不好,看DevelopDoc有点吃力
当我在第 377 行阅读 ThreadPoolExecutor

    private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0));

关于 ctl 的全部内容。

 *   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

我猜答案是'control state***??' 请帮忙 me.Thanks.

正如您在变量 ctl 的注释中看到的,它用于两件事:

  1. 记录线程池有效线程数;
  2. 记录线程池的状态;

在eclipse中用ctrl + k跟踪这个变量,发现里面有一些位操作,所以需要花一些时间去理解里面的算法,你可以在网上找一些源码分析。

猜你是中国人,有一篇source analyze关于ThreadPoolExecutor的中文写的