Spring ThreadPoolTask​​Executor中的corePoolSize和maxPoolSize有什么区别 [英] What is the difference between corePoolSize and maxPoolSize in the Spring ThreadPoolTaskExecutor

查看:430
本文介绍了Spring ThreadPoolTask​​Executor中的corePoolSize和maxPoolSize有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须向网站的所有用户发送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.

推荐答案

javadoc说得最好:

当一个新的 任务已提交[...],并且 少于corePoolSize个线程 运行时,将创建一个新线程来 处理请求,即使其他 工作线程处于空闲状态.如果有 大于corePoolSize但小于 maximumPoolSize个线程正在运行, 仅当 队列已满.通过设置 corePoolSizemaximumPoolSize 同样,您创建一个固定大小 线程池.通过设置 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 than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full. By setting corePoolSize and maximumPoolSize the same, you create a fixed-size thread pool. By setting maximumPoolSize to an essentially unbounded value such as Integer.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 ThreadPoolTask​​Executor中的corePoolSize和maxPoolSize有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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