gpt4 book ai didi

java - ScheduledThreadPoolExecutor 的构造函数中 'core pool size' 的含义

转载 作者:搜寻专家 更新时间:2023-10-30 20:02:32 25 4
gpt4 key购买 nike

我是 ScheduledThreadPoolExecutor 的新手(因为我通常使用简单的 Timer,但人们一直反对它),我不太明白什么会是传递给 ScheduledThreadPoolExecutor(int) 构造函数的适当整数值。

谁能解释一下?

谢谢

最佳答案

ScheduledThreadPoolExecutor 的情况下,corePoolSize 是将创建以执行计划操作的最大线程数。这个线程池是固定大小的,空闲线程保持 Activity 状态。

DrunkenRabbit 的回答完全有效,因为 ScheduledThreadPoolsExecutor 文档明确指出(根本不会出现线程数峰值):

While this class inherits from ThreadPoolExecutor, a few of the inherited tuning methods are not useful for it. In particular, because it acts as a fixed-sized pool using corePoolSize threads and an unbounded queue, adjustments to maximumPoolSize have no useful effect.

现在至于值,合理的数字是应用程序运行的 CPU 核心数。

关于java - ScheduledThreadPoolExecutor 的构造函数中 'core pool size' 的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15888366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com