核心池大小与ThreadPoolExecutor中的最大池大小 [英] Core pool size vs maximum pool size in ThreadPoolExecutor

查看:252
本文介绍了核心池大小与ThreadPoolExecutor中的最大池大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们用ThreadPoolExecutor进行交谈时,核心池大小最大池大小之间到底有什么区别?
可以借助示例进行解释吗?

What exactly is the difference between core pool size and maximum pool size when we talk in terms of ThreadPoolExecutor?
Can it be explained with the help of an example?

推荐答案

来自

以这个例子为例.起始线程池大小为1,核心池大小为 5,最大池大小为10,队列为100.

Take this example. Starting thread pool size is 1, core pool size is 5, max pool size is 10 and the queue is 100.

随着请求的到来, 最多创建5个线程,然后将任务添加到 队列,直到达到100.当队列已满时,将有新线程 最多创建到maxPoolSize.一旦所有线程都被使用,并且 队列已满,任务将被拒绝.随着队列的减少,也是如此 活动线程数.

As requests come in, threads will be created up to 5 and then tasks will be added to the queue until it reaches 100. When the queue is full new threads will be created up to maxPoolSize. Once all the threads are in use and the queue is full tasks will be rejected. As the queue reduces, so does the number of active threads.

这篇关于核心池大小与ThreadPoolExecutor中的最大池大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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