title: How to use decider in Spring batch?
body: <p>I'm new to Spring batch. I've created a decider which returns a FlowExecutionStatus as &quot;YES&quot; / &quot;NO&quot;. Based on the <code>FlowExecutionStatus</code>, I need to call <code>step2()</code> or <code>step3()</code>.</p>
  <p>In my below code, <code>step2()</code> is getting called before decider. How to modify the code so that decider will be called and based on the <code>FlowExecutionStatus</code> returned bu the decider, either <code>step2()</code> or <code>step3()</code> should be called. Please help.</p>
  <pre><code>@Autowired
  private NumberDecider decider;
  
  @Bean
  public Job NumberLoaderJob() throws NumberFormatException, IOException {
      return jobBuilderFactory.get(&quot;numberLoaderJob&quot;).start(step1()).listener(new MyNumberJobListener())
              .next(decider).on(&quot;YES&quot;).to(step2())
              .from(decider).on(&quot;NO&quot;).to(step3()).end().build();
  }
  
  @Bean
  public Step step1() {
  
      return stepBuilderFactory.get(&quot;step1&quot;).tasklet(new Tasklet() {
  
          @Override
          public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
              System.out.println(&quot;Exiting step1() execute()&quot;);
              return RepeatStatus.FINISHED;
          }
      }).build();
  }
  
  /**
   * Step 2
   *
   * @return
   * @throws NumberFormatException
   * @throws IOException
   */
  @Bean
  public Step step2() throws NumberFormatException, IOException {
      return stepBuilderFactory.get(&quot;step2&quot;).listener(new MyStepListener())
              .&lt;OrderNumber, OrderNumber&gt;chunk(Integer.valueOf(chunkSize)).faultTolerant()
              .listener(new MyChunkListener()).reader(new MyItemReader())
              .listener(new MyItemReaderListener()).writer(customItemWriter())
              .listener(new MyWriteListener()).build();
  }
  </code></pre>