You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Integration 6.1线程行为变更致生产环境问题求助

Spring Integration 6.1 升级后顺序执行变并行的修复方案

问题根源

Spring Integration 6.1 对 routeToRecipients 做了破坏性变更:默认行为从同步阻塞等待所有收件人流执行完成改为异步分发、不等待流结束,这直接导致了你的两个收件人流从顺序执行变成并行,进而出现「first flow ended」无法输出、第二个流提前启动的问题。

修复方案

在 routeToRecipients 配置中显式添加 .async(false),强制恢复6.0版本的同步阻塞行为,让收件人流依次执行,等待当前流全流程完成后再启动下一个流。

修改后的示例代码

.routeToRecipients(route -> route
        .async(false) // 关键配置:恢复同步阻塞,保证收件人流顺序执行
        .recipientFlow(flow -> flow
                .log(INFO, logCat, m -> "first flow started")
                .scatterGather(
                        scatterer -> scatterer
                                .applySequence(true)
                                .recipientFlow(innerFlow -> innerFlow
                                        .channel(c -> c.executor(executorService))
                                        .log(INFO, logCat, m -> "subflow started")
                                        .transform(source -> {
                                            try {
                                                Thread.sleep(1000 * 40);
                                            } catch (InterruptedException e) {
                                                throw new RuntimeException(e);
                                            }
                                            return source;
                                        })
                                        .log(INFO, logCat, m -> "subflow ended")
                                        .bridge()),
                        gatherer -> gatherer.releaseStrategy(group -> {
                            log.info("group size {}", group.size());
                            return group.size() == 1;
                        }))
                .log(INFO, logCat, m -> "first flow ended")
                .nullChannel()
        )
        .recipientFlow(flow -> flow
                .log(INFO, logCat, m -> "second flow started")
                .nullChannel()
        )
)

修复效果说明

  1. 添加 .async(false) 后,routeToRecipients 会等待第一个收件流的全流程(包括内部scatter-gather的异步子流聚合完成)执行完毕,才会启动第二个收件流,解决「second flow started」提前启动的问题。
  2. 第一个流中的「first flow ended」日志会在scatter-gather聚合完成后正常输出,因为主线程会等待整个流处理完成再继续。

内容的提问来源于stack exchange,提问作者Chris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 22:23:27