繁体   English   中英

为什么在 spring 批处理中不调用分流?

[英]Why splitted flow is not invoked in 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 为什么? 我该如何纠正?

更新

@Bean
public TaskExecutor jobTaskExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    // there are 21 sites currently hence we have 21 threads
    taskExecutor.setMaxPoolSize(30);
    taskExecutor.setCorePoolSize(25);
    taskExecutor.setThreadGroupName("cust-job-exec-");
    taskExecutor.setThreadNamePrefix("cust-job-exec-");
    taskExecutor.afterPropertiesSet();
    return taskExecutor;
}

不支持向状态链添加拆分,这是执行所需操作的正确方法(同步任务 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 结束

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&lt;SimpleFlow&gt;("ComplexParallelFlow")
     *                       .start(flow1)
     *                       .next(flow2)
     *                       .split(new SimpleAsyncTaskExecutor())
     *                       .add(flow3, flow4)
     *                       .build();
     *
     * // do this
     * Flow splitFlow = new FlowBuilder&lt;SimpleFlow&gt;("parallelFlow")
     *                       .start(flow3)
     *                       .split(new SimpleAsyncTaskExecutor())
     *                       .add(flow4).build();
     *
     * Flow complexFlow = new FlowBuilder&lt;SimpleFlow&gt;("ComplexParallelFlow")
     *                       .start(flow1)
     *                       .next(flow2)
     *                       .next(splitFlow)
     *                       .build();
     * </pre>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM