gpt4 book ai didi

spring - Spring 的 DefaultMessageListenerContainer 中 taskExecutor 属性的用途

转载 作者:行者123 更新时间:2023-12-04 04:41:39 27 4
gpt4 key购买 nike

Spring 的DefaultMessageListenerContainer (DMLC) 有 concurrentConsumertaskExecutor属性(property)。可以给出 taskExecutor bean corePoolSize属性(property)。那么指定 concurrentConsumer 和 corePoolSize 之间有什么区别?当定义 concurrentConsumer 属性时,意味着 Spring 将创建指定数量的消费者/messageListeners 来处理消息。 corePoolSize 什么时候出现?

代码片段

<bean id="myMessageListener"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="myQueue" />
<property name="messageListener" ref="myListener" />
<property name="cacheLevelName" value="CACHE_CONSUMER"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="concurrentConsumers" value="3"/>
<property name="taskExecutor" ref="myTaskExecutor"/>
</bean>

<bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" >
<property name="corePoolSize" value="100"/>
<property name="maxPoolSize" value="100"/>
<property name="keepAliveSeconds" value="30"/>
<property name="threadNamePrefix" value="myTaskExecutor"/>
</bean>

最佳答案

根据 4.3.6 版本,taskExecutor包含 AsyncMessageListenerInvoker 的实例它负责消息处理。 corePoolSize是定义池中的物理线程数,而concurrentConsumer是这个池中的一些任务。我猜这个抽象是为了更灵活的控制而设计的。

关于spring - Spring 的 DefaultMessageListenerContainer 中 taskExecutor 属性的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15921684/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com