相关疑难解决方法(0)

为什么ScheduledThreadPoolExecutor只接受固定数量的线程?

我可以想象一些任务计划花费很长时间,并ScheduledThreadPoolExecutor为其他需要运行的任务创建额外的线程,直到达到最大线程数.

但似乎我只能为池指定固定数量的线程,为什么会这样呢?

java threadpool

31
推荐指数
2
解决办法
7911
查看次数

ScheduledExecutorService是否会根据需要创建新线程?

我正在Executors.newScheduledThreadPool()创建一个ScheduledExecutorService,指定线程数如下:

int corePoolSize = 42;
ScheduledExecutorService foo = Executors.newScheduledThreadPool(corePoolSize);
Run Code Online (Sandbox Code Playgroud)

根据JavaDocs,corePoolSize参数设置

即使它们处于空闲状态,也要保留在池中的线​​程数.

这是否意味着此ExecutorService实现可能会corePoolSize根据需要创建多个线程,类似于缓存的线程池

java executorservice

14
推荐指数
2
解决办法
9212
查看次数

标签 统计

java ×2

executorservice ×1

threadpool ×1