Spring 批处理 3.0.2 使用注释的并行步骤

Spring Batch 3.0.2 Parallel Steps using Annotations

我正在使用 SpringBatch 3.0.2 并尝试创建一个作业,该作业使用带有注释和 JobBuilderFactory class 的 JavaConfig 样式执行一系列步骤(其中一些是并行的)。我想要发生的是从 step1 开始,当它完成过渡到 step2a、step2b、step2c 和 step2d 时,所有 运行 并行。当所有这些步骤完成后,它应该过渡到第 3 步。我正在努力使用创建此作业所需的语法

@Bean(name = "SplitFlowJob4")
 public Job splitFlowJob4() throws SQLException
  {
    final Flow flow2b = new FlowBuilder<Flow>("subflow2b").from(step2b()).end();
    final Flow flow2c = new FlowBuilder<Flow>("subflow2c").from(step2c()).end();
    final Flow flow2d = new FlowBuilder<Flow>("subflow2d").from(step2d()).end();

    return jobs.get("SplitFlowJob4").start(step1()).next(step2a()).split(new SimpleAsyncTaskExecutor())
        .add(flow2b, flow2c, flow2d).next(step3()).end().build();
  }

这不符合我的预期。这只执行 step1 和 step2a。我没有看到 step2b、2c、2d 或 step3。

    [INFO ] [main] 2015-02-09 15:28:32,169 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep1]
    [INFO ] [main] 2015-02-09 15:28:32,194 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2a]

如果我更改语法并从步骤 1 调用拆分,则步骤 1、2a、2b、2c、2d 全部并行执行,而不仅仅是步骤 2a、2b、2c、2d。

  @Bean(name = "SplitFlowJob5")
  public Job splitFlowJob5() throws SQLException
  {
    final Flow flow2a = new FlowBuilder<Flow>("subflow2a").from(step2a()).end();
    final Flow flow2b = new FlowBuilder<Flow>("subflow2b").from(step2b()).end();
    final Flow flow2c = new FlowBuilder<Flow>("subflow2c").from(step2c()).end();
    final Flow flow2d = new FlowBuilder<Flow>("subflow2d").from(step2d()).end();

    return jobs.get("SplitFlowJob5").start(step1()).split(new SimpleAsyncTaskExecutor())
        .add(flow2a, flow2b, flow2c, flow2d).next(step3()).end().build();
  }

这将并行执行 Step1、step2a、step2b、step2c、step2d。

    [INFO ] [SimpleAsyncTaskExecutor-2] 2015-02-09 16:28:36,507 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2b]
    [INFO ] [SimpleAsyncTaskExecutor-5] 2015-02-09 16:28:36,513 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep1]
    [INFO ] [SimpleAsyncTaskExecutor-3] 2015-02-09 16:28:36,512 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2c]
    [INFO ] [SimpleAsyncTaskExecutor-4] 2015-02-09 16:28:36,509 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2d]
    [INFO ] [SimpleAsyncTaskExecutor-1] 2015-02-09 16:28:36,507 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep2a]
    [INFO ] [main] 2015-02-09 16:28:36,615 org.springframework.batch.core.job.SimpleStepHandler - Executing step: [SplitFlowJobStep3]

我不确定我做错了什么,是否可以使用流利的生成器创建这样的工作api?我见过其他以拆分开始或结束的工作示例,但我还没有看到在作业中间包含拆分的示例。

Spring Batch 的 java 配置中存在一个错误,该错误已于上周晚些时候修复 (BATCH-2346)。那里的修复解决了阻止列表中第一个流程执行的错误,以及关于如何解决这个用例的文档修复。

简而言之,以下代码应该适用于最新代码:

@Bean(name = "SplitFlowJob5")
public Job splitFlowJob5() throws SQLException
{
    final Flow flow2a = new FlowBuilder<Flow>("subflow2a").from(step2a()).end();
    final Flow flow2b = new FlowBuilder<Flow>("subflow2b").from(step2b()).end();
    final Flow flow2c = new FlowBuilder<Flow>("subflow2c").from(step2c()).end();
    final Flow flow2d = new FlowBuilder<Flow>("subflow2d").from(step2d()).end();

    final Flow splitFlow = new FlowBuilder<Flow>("splitFlow")
        .start(flow2a)
        .split(new SimpleAsyncTaskExecutor())
        .add(flow2b, flow2c, flow2d).build();

    return jobs.get("SplitFlowJob5").start(step1())
       .next(splitFlow).next(step3()).end().build();
}