Question

I have a JMS Message Listener under JBoss 5.1, configured by Spring. Although the ThreadPoolTaskExecutor is configured to have a core pool size of 15, I see that only one thread is serving requests, and the others are waiting. According to the ThreadPoolExecutor API I need to have a bounded queue, but I don't see how spring allow me to do it.

Here is the configuration:

<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/ConnectionFactory" />
    <property name="jndiTemplate" ref="jndiTemplate" />
</bean>

<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="queue/someQueue" />
    <property name="jndiTemplate" ref="jndiTemplate" />
</bean>

<bean id="jmsReceiveDestinationResolver"
    class="org.springframework.jms.support.destination.JndiDestinationResolver">
    <property name="jndiTemplate" ref="jndiTemplate" />
</bean>

<bean id="someListener" class="com.company.SomeListener">
    <property name="..." ref="..." />
</bean>

<jms:listener-container connection-factory="connectionFactory"
    destination-type="queue" destination-resolver="jmsReceiveDestinationResolver" 
    task-executor="jmsTaskExecutor">
    <jms:listener destination="queue/someQueue" ref="messageListener" />
</jms:listener-container>

<bean name="jmsTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="15"/>
    <property name="maxPoolSize" value="50"/>       
    <property name="threadNamePrefix" value="some-queue-thread"/>
</bean>

Here is the stack trace of the 14 waiting threads:

"some-queue-thread7" prio=10 tid=0x000000004dcfc800 nid=0x1d90 waiting on condition [0x00000000435f7000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x000000070f5abad8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1987)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:662)

Notice this may similar to Spring ThreadPoolTaskExecutor only running one thread, but in my case the core pool size is larger than 1.

Was it helpful?

Solution

Spring Reference says that you need to specify maximum number of concurrent consumers with <jms:listener-container concurrency = "15" ...>, otherwise it would be 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top