ScheduledThreadPoolExecutor 的构造函数中“核心池大小"的含义 [英] meaning of 'core pool size' in ScheduledThreadPoolExecutor's constructor

查看:51
本文介绍了ScheduledThreadPoolExecutor 的构造函数中“核心池大小"的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to ScheduledThreadPoolExecutor (as I usually use the simple Timer, but people have been advising against it), and I don't quite understand what would be the appropriate integer value to pass to the ScheduledThreadPoolExecutor(int) constructor.

谁能解释一下?

谢谢

推荐答案

ScheduledThreadPoolExecutor 的情况下,corePoolSize 是为执行计划操作而创建的最大线程数.这个线程池是固定大小的,空闲线程保持活动状态.

In case of ScheduledThreadPoolExecutor, corePoolSize is maximum number of threads that will be created to perform scheduled actions. This thread pool is fixed-sized and idle threads are kept alive.

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

DrunkenRabbit's answer is simply ivalid because ScheduledThreadPoolsExecutor docs says explicitly that (There will be no thread count spikes at all):

虽然这个类继承自 ThreadPoolExecutor,但有一些继承的调整方法对它没有用.特别是,因为它作为一个固定大小的池使用 corePoolSize 线程和一个无界队列,调整maximumPoolSize没有任何作用.

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 内核数.

Now as for the value, reasonable number would be number of CPU cores that application is running on.

这篇关于ScheduledThreadPoolExecutor 的构造函数中“核心池大小"的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆