I am using a SimpleAsyncTaskExecutor inside of my DefaultMessageListenerContainer and I would like to monitor the active thread count using a JMX mbean. I have the mbean created and connected, but in monitoring on JConsole, the active thread count on the taskExecutor remains at the value it is created with. It doesn't fluctuate as the DMLC receives inbound messages. Shouldn't this number be fluctuating? Here is the writeup from Spring on the SimpleAsyncTaskExecutor:
SimpleAsyncTaskExecutor: This implementation does not reuse any threads, rather it starts up a new thread for each invocation. However, it does support a concurrency limit which will block any invocations that are over the limit until a slot has been freed up. If you’re looking for true pooling, keep scrolling further down the page. Spring Framework Task Execution and Scheduling
Here is my setup using Spring-jms 3.0.3.RELEASE:
<bean id="inboundMessageAdaptorMessageContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="singleJMSConnectionFactory" />
<property name="destination" ref="eventReceiveQueue" />
<property name="sessionTransacted" value="true" />
<property name="messageListener" ref="inboundMessageRetryingListenerAdapter" />
<property name="concurrentConsumers" value="15" />
</bean>
My Mbean exposes fields in the DMLC. It grabs the private field threadCount on the super class of the TaskExecutor:
Field taskExecutorField = dmlc.getClass().getDeclaredField("taskExecutor");
taskExecutorField.setAccessible(true);
taskExecutor = (SimpleAsyncTaskExecutor) taskExecutorField.get(dmlc);
threadCountField = taskExecutor.getClass().getSuperclass().getDeclaredField("threadCount");
threadCountField.setAccessible(true);
return (int) threadCountField.get(taskExecutor);
I've tried tweaking with settings on the DMLC like IdleTaskExecutionLimit and CacheLevel, but they did not achieve my goal. I'd like to be able to find something that does not involve creating new classes or adding additional methods to concrete classes.