猿问

为什么在 spring batch 中不调用拆分流?

我有以下工作配置:


@Bean

public Job job(Step databaseToDataBaseLowercaseSlaveStep) {

    return jobBuilderFactory.get("myJob")

            .incrementer(new RunIdIncrementer())

            .flow(csvToDbLowercaseStep())

            .next(databaseToDataBaseLowercaseSlaveStep)

            .split(jobTaskExecutor())

            .add(new FlowBuilder<Flow>("flow2")

                    .start(notificationStep())

                    .build()

            )

            .end()

            .build();

}

预期的行动顺序

  1. 执行csvToDbLowercaseStep

  2. 并行运行 2 个步骤 a) databaseToDataBaseLowercaseSlaveStep b)notificationStep

实际行动顺序

  1. 执行csvToDbLowercaseStep

  2. 执行databaseToDataBaseLowercaseSlaveStep

所以notificationStep根本没有被调用。为什么?我该如何纠正它?


白猪掌柜的
浏览 115回答 1
1回答

陪伴而非守候

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

相关分类

Java
我要回答