首页 文章

SimpleMessageListenerContainer和TaskExecutor始终只处理1条消息

提问于
浏览
1

我有 SimpleMessageListenerContainer 使用 TaskExecutor (池大小= 15),一次不会处理多于1条消息 . 以下是它的配置方式 .

SimpleMessageListenerContainer设置为:

concurrentConsumers = 1 (e.g., 1 JMS consumer)
taskExecutor = instance of java.util.concurrent.ThreadPoolExecutor

ThreadPoolExecutor设置为:

corePoolSize = 1
maximumPoolSize= 15
workQueue = LinkedBlockingQueue<Runnable> with size 200

我的期望:

我希望1 JMS使用者能够在其中一个后台taskExecutor线程中拉出消息并尽可能快地运行它们 . 如果队列中有50条消息,它将全部撤消50.一次运行15,而另外35条消息保存在taskExecutor的 LinkedBlockingQueue 内部队列中 .

实际发生了什么:

相反,我的应用程序一次处理1条消息 . 在JConsole中,我扩展了容器并公开了有关任务执行程序状态的更多JMX属性,我看到"taskExecutor" activeCount最大为1(例如ThreadPoolExecutor.getActiveCount()) . ThreadPoolExecutor 永远不会移动到15.因此,即使使用线程池为15的taskExecutor处理消息,JMS Consumer仍然一次处理1条消息 .

以下是JConsole JMX读数在我用大量消息填充队列后显示的内容 .

  • ConcurrentConsumers =映射到Spring的SimpleMessageContainer.concurrentConsumers

  • ActiveCount =映射到ThreadPoolExecutor.activeCount

  • MinConcurrentConsumers =映射到ThreadPoolExecutor.corePoolSize

  • MaxConcurrentConsumers =映射到ThreadPoolExecutor.maximumPoolSize

  • InternalQueueCapacity =映射到ThreadPoolExecutor的LinkedBlockingQueue大小 .

enter image description here

我错过了什么?我是否需要使用Executor的不同实现?

1 回答

  • 0

    我发现此链接有助于解决此问题:

    how to configure ThreadPoolExecutor to grow/shrink

    我的corePoolSize是1,在内部,ThreadPoolExecutor只是将消息排队并使用该单核心线程处理排队的消息 . 将corePoolSize设置得更高可以增加我想要的线程数 .

相关问题