title: Spring Batch process unable to run flows in parallel
body: <p>I have a Spring batch application in which I am trying to run two steps in parallel by defining them on flowbuilder and in every stepbuilderfactory I have defined a custom partition and I am running the step in multiple threads.</p>
  <pre><code>@Bean
      public Job job() throws Exception {
  return jobBuilderFactory.get(&quot;Spring_batch&quot;).split(new SimpleAsyncTaskExecutor()).add(flow1(),flow2()).build().build();
  }
  </code></pre>
  <p>flow 1:</p>
  <pre><code>@Bean
      public Flow flow1() throws Exception {
          return new FlowBuilder&lt;Flow&gt;(&quot;Flow&quot;)
                  .start(stepBuilderFactory.get(&quot;MasterStep1&quot;).partitioner(SlaveStep().getName(), partitioner())
                          .step(SlaveStep()).gridSize(4).taskExecutor(new SimpleAsyncTaskExecutor()).build())
                  .build();
      }
  </code></pre>
  <p>Step for flow 1:</p>
  <pre><code>@Bean
      public Step SlaveStep() throws Exception {
          return stepBuilderFactory.get(&quot;flow1slaveStep&quot;).&lt;Person, Person&gt;chunk(100)
                  .reader(new jdbcPagingItemReader(input1, input2)).writer(new ItemWriter()).build();
      }
  </code></pre>
  <p>flow 2:</p>
  <pre><code>@Bean
      public Flow flow2() throws Exception {
          return new FlowBuilder&lt;Flow&gt;(&quot;Flow-2&quot;)
                  .start(stepBuilderFactory.get(&quot;MasterStep2&quot;).partitioner(FlowSlaveStep().getName(), secondPartitioner())
                          .step(FlowSlaveStep()).gridSize(4).taskExecutor(new SimpleAsyncTaskExecutor()).build())
                  .build();
      }
  </code></pre>
  <p>Step for flow 2:</p>
  <pre><code>@Bean
      public Step FlowSlaveStep() throws Exception {
          return stepBuilderFactory.get(&quot;flow2slaveStep&quot;).&lt;Person, Person&gt;chunk(100)
                  .reader(new jdbcPagingItemReader(input1, input2)).writer(new ItemWriter()).build();
      }
  </code></pre>
  <p>Both the steps use same ItemReader and ItemWriter but with different inpits they get from partitions.<br/><br/>
  when I am running it the program works fine till it completes running custom partitions in both the flows but both the flows are waiting after completing the custom partitions and not going to itemReaders. I have an <code>StoredProcedureItemReader</code> defined with inputs. I am not sure how I can get my code to complete executing both the flows in parallel. <br/><br/>When I am trying to run the flows one after the other they run perfectly fine like:</p>
  <pre><code>@Bean
  public Job job() throws Exception {
      return jobBuilderFactory.get(&quot;Spring_batch&quot;).start(flow1()).next(flow2()).end().build();
  }
  </code></pre>
  <p>Please suggest me what I can do to achieve parallel flows on the steps which hits the same <code>StoredProcedureItemReader</code>.</p>