2016-04-26 94 views

回答

3

您可以在上下文文件規定流量控制,像這樣:在你的Tasklet

<step id="step1"> 
    <tasklet ref="example"> 
    <next on="COMPLETED" to="step2" /> 
    <end on="NO-OP" /> 
    <fail on="*" /> 
    <!-- 
     You generally want to Fail on * to prevent 
     accidentally doing the wrong thing 
    --> 
</step> 

然後,通過實施StepExecutionListener

public class SampleTasklet implements Tasklet, StepExecutionListener { 

    @Override 
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { 
     // do something 
     return RepeatStatus.FINISHED; 
    } 

    @Override 
    public void beforeStep(StepExecution stepExecution) { 
     // no-op 
    } 

    @Override 
    public ExitStatus afterStep(StepExecution stepExecution) { 
     //some logic here 
     boolean condition1 = false; 
     boolean condition2 = true; 

     if (condition1) { 
      return new ExitStatus("COMPLETED"); 
     } else if (condition2) { 
      return new ExitStatus("FAILED"); 
     } 

     return new ExitStatus("NO-OP"); 
    } 

} 
設置退出狀態