首页 > 解决方案 > 分配给 ThreadPoolExecutor 的静态变量

问题描述

我尝试将静态变量分配为 ThreadPoolExecutor 的参数。

Public class MyClass{

   private static final int corePoolSize;
   static{
      corePoolSize= 30;
   }

   private static ExecutorService executorService = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,threadFactory)

 ...
}

上线失败。

如果我直接将值传递给 threadpollexecutor,下面的一个是没有问题的

private static ExecutorService executorService = new ThreadPoolExecutor(30, maximumPoolSize, keepAliveTime, unit, workQueue,threadFactory)

标签: javavariablesstaticthreadpoolexecutor

解决方案


推荐阅读