ScheduledThreadPoolExecutor 的构造函数中“核心池大小"的含义

编程入门 行业动态 更新时间:2024-10-26 18:29:17
本文介绍了ScheduledThreadPoolExecutor 的构造函数中“核心池大小"的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我是 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 16:38:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   含义   大小   核心   ScheduledThreadPoolExecutor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!