gpt4 book ai didi

java - Spring - DefaultMessageListenerContainer TaskExecutor 线程监控

转载 作者:行者123 更新时间:2023-12-01 12:45:19 27 4
gpt4 key购买 nike

我在 DefaultMessageListenerContainer 内使用 SimpleAsyncTaskExecutor,并且我想使用 JMX mbean 监视 Activity 线程计数。我创建并连接了 mbean,但在 JConsole 上进行监视时,taskExecutor 上的 Activity 线程计数仍保持其创建时的值。当 DMLC 接收入站消息时,它不会波动。这个数字不应该波动吗?以下是 Spring 关于 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

这是我使用 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>

我的 Mbean 公开 DMLC 中的字段。它获取 TaskExecutor 父类(super class)上的私有(private)字段 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);

我尝试过调整 DMLC 上的设置像IdleTaskExecutionLimit和CacheLevel,但他们没有达到我的目标。我希望能够找到一些不涉及创建新类或向具体类添加其他方法的东西。

最佳答案

没有;仅当 maxConcurrentConsumers 大于 concurrentConsumers 时才会波动,在这种情况下,容器将根据需要调整线程。

关于java - Spring - DefaultMessageListenerContainer TaskExecutor 线程监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24763690/

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