我有一个camelRoute,应该在拆分中使用threadPool来进行并行工作。我的问题是,我总是以一个线程结束太多,因为拆分将运行一个线程,并且线程池将运行指定数量的线程。 我希望线程池限制线程数量。
任何人都可以看到为什么会这样吗?下方的路线和 Camel 语境...(代码中的其他值,例如from和id等,但此处无法显示出来...)
from(FROM_ENDPOINT)
.routeId(ID)
.split(body(), new GroupedExchangeAggregationStrategy())
.executorServiceRef("ThreadPool")
.bean(bean, "beanMethod")
.end()
.bean(bean)
.multicast()
.to(TO_ENDPOINT);
在我的camel-context.xml中像这样配置ThreadPool:
<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个后台线程留出空间。
关于multithreading - Apache Camel拆分与线程池并行运行,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43913776/