简体   繁体   English

春季-DefaultMessageListenerContainer TaskExecutor线程监视

[英]Spring - DefaultMessageListenerContainer TaskExecutor Thread monitoring

I am using a SimpleAsyncTaskExecutor inside of my DefaultMessageListenerContainer and I would like to monitor the active thread count using a JMX mbean. 我在DefaultMessageListenerContainer内使用SimpleAsyncTaskExecutor,我想使用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. 我已经创建并连接了mbean,但是在JConsole上进行监视时,taskExecutor上的活动线程数仍保持为创建时的值。 It doesn't fluctuate as the DMLC receives inbound messages. 随着DMLC接收入站消息,它不会波动。 Shouldn't this number be fluctuating? 这个数字不应该波动吗? Here is the writeup from Spring on the SimpleAsyncTaskExecutor: 这是Spring在SimpleAsyncTaskExecutor上的文章:

SimpleAsyncTaskExecutor: This implementation does not reuse any threads, rather it starts up a new thread for each invocation. SimpleAsyncTaskExecutor: 此实现不重用任何线程,而是为每次调用启动一个新线程。 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 Spring框架任务执行和调度

Here is my setup using Spring-jms 3.0.3.RELEASE: 这是我使用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. 我的Mbean公开了DMLC中的字段。 It grabs the private field threadCount on the super class of the TaskExecutor: 它在TaskExecutor的超类上获取私有字段threadCount:

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. 我曾尝试对DMLC上的设置(如IdleTaskExecutionLimit和CacheLevel)进行调整,但是它们并没有达到我的目标。 I'd like to be able to find something that does not involve creating new classes or adding additional methods to concrete classes. 我希望能够找到不涉及创建新类或向具体类添加其他方法的内容。

No; 没有; it will only fluctuate if maxConcurrentConsumers is greater than concurrentConsumers , in which case, the container will adjust the threads on demand. 它只会出现波动,如果maxConcurrentConsumers大于concurrentConsumers ,在这种情况下,容器将调整对需求的线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM