Spring ThreadPoolTask​​Executor永远不会超越corePoolSize

时间:2014-07-15 13:13:15

标签: java multithreading spring threadpool

我已经配置了Spring ThreadPoolTask​​Executor,根据需要考虑至少16个线程,最多256个:

<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

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

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

1 个答案:

答案 0 :(得分:9)

知道了:

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

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