Apache Camel与ThreadPool并行运行,为什么



我有一个驼峰路由,它应该在拆分中使用线程池来执行并行工作。我的问题是我总是以一个线程结束太多,因为拆分将运行一个线程,线程池将运行指定数量的线程。我希望线程池限制线程数量。

任何人都能明白为什么会这样?路线和骆驼背景如下...(代码中的其他值,如 from 和 id 等,但在这里无法显示......

from(FROM_ENDPOINT)
    .routeId(ID)
    .split(body(), new GroupedExchangeAggregationStrategy())
    .executorServiceRef("ThreadPool")
    .bean(bean, "beanMethod")
    .end()
    .bean(bean)
    .multicast()
    .to(TO_ENDPOINT);

线程池在我的骆驼上下文中是这样配置的.xml:

<camel:camelContext id="application-context" useMDCLogging="true" xmlns="http://camel.apache.org/schema/spring">
    <propertyPlaceholder id="properties" location="ref:props"/>
    <routeBuilder ref="refToRoute"/>
    <threadPoolProfile id="ThreadPool" maxPoolSize="2"
                       maxQueueSize="-1" poolSize="2"/>
</camel:camelContext>

拆分器需要一个后台线程来编排并行工作。因此,您有线程池中的线程+一个名为Splitter-AggregateTask的额外线程。

因此,如果您希望总最大值为 10,则将线程池大小设置为 9,以便您也有空间容纳 1 个后台线程。

最新更新