本文介绍了Spring ThreadPoolTask​​Executor永远不会超出corePoolSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置了Spring ThreadPoolTask​​Executor,考虑到至少16个线程,并且在需要的基础上最多有256个线程:

I have configured Spring ThreadPoolTaskExecutor, having in mind 16 threads at least and up to 256 on the need-basis:

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="16"/>
    <property name="maxPoolSize" value="256"/>
    <property name="queueCapacity" value="256"/>
</bean>

但是从日志中可以看到,线程池的大小永远不会超过 corePoolSize :

But as I can see from logs, thread pool size never exceeds corePoolSize:

Thread pool size: 16/256, active count: 16

为什么会这样?我做错了什么?

Why is that so? What have I done wrong?

推荐答案

知道了:

If there are more than corePoolSize but less
than maximumPoolSize threads running,
a new thread will be created only if the queue is full.

所以解决方案是缩小队列!

So the solution is to shrink the queue!

这篇关于Spring ThreadPoolTask​​Executor永远不会超出corePoolSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-14 19:50