Spring ThreadPoolTaskExecutor中的corePoolSize和maxPoolSize有什么区别 [英] What is the difference between corePoolSize and maxPoolSize in the Spring ThreadPoolTaskExecutor
问题描述
我必须向网站的所有用户发送massEmail.我想为每个发送的电子邮件使用一个线程池.目前,我已将值设置为:
I have to send out massEmails to all users of a website. I want to use a thread pool for each email that is sent out. Currently I have set the values to :
<property name="corePoolSize" value="500" />
<property name="maxPoolSize" value="1000" />
两者之间的区别是什么,它将扩展.目前我有大约. 10000个用户.
What is the difference between the two and will it scale. Currently I have approx. 10000 users.
推荐答案
当一个新的 任务已提交[...],并且 少于
corePoolSize
个线程 运行时,将创建一个新线程来 处理请求,即使其他 工作线程处于空闲状态.如果有 大于corePoolSize
但小于maximumPoolSize
个线程正在运行, 仅当 队列已满.通过设置corePoolSize
和maximumPoolSize
同样,您创建一个固定大小 线程池.通过设置maximumPoolSize
到本质上 无限值,例如Integer.MAX_VALUE
,您允许 池以容纳任意 并发任务数.
When a new task is submitted [...], and fewer than
corePoolSize
threads are running, a new thread is created to handle the request, even if other worker threads are idle. If there are more thancorePoolSize
but less thanmaximumPoolSize
threads running, a new thread will be created only if the queue is full. By settingcorePoolSize
andmaximumPoolSize
the same, you create a fixed-size thread pool. By settingmaximumPoolSize
to an essentially unbounded value such asInteger.MAX_VALUE
, you allow the pool to accommodate an arbitrary number of concurrent tasks.
对于您的特定情况,一次发送500封电子邮件毫无意义,您将使邮件服务器不堪重负.如果您需要发送大量电子邮件,请使用一个线程,然后一次通过管道发送一次.邮件服务器将比500个单独的连接更优雅地处理此问题.
As for your specific situation, sending 500 emails all at the same time is pointless, you'll just overwhelm the mail server. If you need to send a large number of emails, then use a single thread, and send them down the pipe one at a time. The mail server will handle this much more gracefully than 500 separate connections.
这篇关于Spring ThreadPoolTaskExecutor中的corePoolSize和maxPoolSize有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!