Pivotal Knowledge Base


Listener Defined in DefaultMessageListener is Not Scaling Even Though a taskExecutor is Defined


 Product  Version
 Spring  All


If the Listener defined in DefaultMessageListener is not scaling or even when a taskExecutor is defined, the DefaultMessageListener isn't scaling. 


If you scale your tasks by defining a taskExecutor in your defaultMessageListener, you may have this spring configuration:

<property name="connectionFactory" ref="taskListenerConnectionPool" />

<property name="messageListener" ref="myTaskListener" />
<property name="taskExecutor" ref="myTaskExecutor" />

<!-- this bean contains your onMessage Method -->

<bean id="myTaskListener" class="com.listener.MessageListener"/>

<bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="1"/>
<property name="maxPoolSize" value="45"/>

Note: You may notice that your active count and size of your taskExecutor is not increasing even though you have a lot of requests.


The corePoolSize indicates the core number of threads. Try raising your corePoolSize higher than 1 so that tasks run serially.

If the core number of threads are busy or unavailable tasks are queued up, the default queue capacity of the ThreadPoolExecutor is set up to Integer.MAX_Value. If the queueCapacity is reached, additional threads are created until it reaches MaxPoolSize.

If you do not want messages to queue up, lower the queue capacity. You might also want to set the allowCoreThreadTimeOut to true, which means that it will scale up until corePoolSize but also scale down if no tasks come in.


Powered by Zendesk