关于ThreadPoolExecutor成员变量

时间:2017-09-01 08:02:12

标签: java threadpoolexecutor

用我糟糕的英语阅读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

我猜答案是'控制状态*** ??' 请帮帮我。谢谢。

1 个答案:

答案 0 :(得分:0)

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

  1. 记录线程池中的有效线程数;
  2. 记录线程池的状态;
  3. 通过在eclipse中使用ctrl + k跟踪此变量,我发现它包含一些位操作,因此需要一些时间来理解内部的算法,您可以在线找到一些源分析。

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