1 回答
TA贡献1757条经验 获得超8个赞
不支持向状态链添加拆分,这是执行所需操作的正确方法(任务 1 同步后跟任务 2 和 3 并行):
public Job job() {
final Flow masterFlow = new FlowBuilder<Flow>("flow1").start(step("step1")).build();
final Flow slaveFlow = new FlowBuilder<Flow>("flow2").split(new SimpleAsyncTaskExecutor())
.add(
new FlowBuilder<Flow>("flow2.1").start(step("step2.1")).build(),
new FlowBuilder<Flow>("flow2.2").start(step("step2.2")).build())
.build();
return (jobBuilderFactory
.get("job")
.incrementer(new RunIdIncrementer())
.start(masterFlow)
.next(slaveFlow)
.build())
.build();
}
private TaskletStep step(final String name) {
return stepBuilderFactory.get(name)
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
System.out.println(name + " start");
Thread.sleep(1000);
System.out.println(name + " end");
return RepeatStatus.FINISHED;
})
.build();
}
step1 开始
step1结束
step2.1开始
step2.2开始
step2.1结束
step2.2结束
希望这可以帮助。
更新
您的代码试图将拆分添加到状态链中,并且根据 FlowBuilder.SplitBuilder 的文档,它根本不受支持。
* <em>Note:</em> Adding a split to a chain of states is not supported. For example, the following configuration
* is not supported. Instead, the configuration would need to create a flow3 that was the split flow and assemble
* them separately.
*
* <pre>
* // instead of this
* Flow complexFlow = new FlowBuilder<SimpleFlow>("ComplexParallelFlow")
* .start(flow1)
* .next(flow2)
* .split(new SimpleAsyncTaskExecutor())
* .add(flow3, flow4)
* .build();
*
* // do this
* Flow splitFlow = new FlowBuilder<SimpleFlow>("parallelFlow")
* .start(flow3)
* .split(new SimpleAsyncTaskExecutor())
* .add(flow4).build();
*
* Flow complexFlow = new FlowBuilder<SimpleFlow>("ComplexParallelFlow")
* .start(flow1)
* .next(flow2)
* .next(splitFlow)
* .build();
* </pre>
添加回答
举报