【发布时间】:2021-04-13 16:46:44
【问题描述】:
我有一个多线程项目,我从队列中读取消息并将其传递给 spring 集成来处理它。每条消息通过 diff 通道最终存储在 DB 中并发送到下游 Q。
<int:channel id="mainChannel">
<int:interceptors>
<int:wire-tap channel="channel1" selector-expression="!headers['somevalue']"/>
<int:wire-tap channel="channel2" selector-expression="!headers['somevalue']"/>
<int:wire-tap channel="channel3" selector-expression="!headers['somevalue']"/>
</int:interceptors>
</int:channel>
<int:channel id="channel1">
<int:dispatcher task-executor="exec1" />
</int:channel>
<int:channel id="channel2">
<int:dispatcher task-executor="exec2" />
</int:channel>
<int:channel id="channel3">
<int:dispatcher task-executor="exec3" />
</int:channel>
现在我想阻塞发送者线程,直到所有异步任务都完成处理,例如,在线程中,只有一条消息进入所有通道(1,2,3),而对于另一个线程,它只会进入 2 个通道(1 ,2) 等等。
我见过聚合器/线程屏障方法,但不确定它是如何工作的,因为每个线程的流都是不同的。
我怎样才能做到这一点?
【问题讨论】:
标签: java multithreading spring-integration