Question

I'm using Spring Batch for the first time. I tried some examples and read through documentation. But I have still questions:

  • Can I skip one phase in chunk oriented processing? For example: I fetch data from database, process it and determine, that I need more, can I skip write phase and execute next step's read phase? Should I use Tasklet instead?

  • How to implement a conditional flow?

Thank you very much, Florian

Was it helpful?

Solution

Skip chunks simply by throwing an exception that has been declared as "skippable exception". You can do it as follows:

<step id="step1">
   <tasklet>
      <chunk reader="reader" writer="writer"
             commit-interval="10" skip-limit="10">
         <skippable-exception-classes>
            <include class="com.myapp.batch.MyException"/>
         </skippable-exception-classes>
      </chunk>
   </tasklet>
</step>

Conditional flow can easily be implemented deciding on the ExitStatus of a step-execution:

<job id="job">
    <step id="step1" parent="s1">
        <next on="*" to="stepB" />
        <next on="FAILED" to="stepC" />
    </step>
    <step id="stepB" parent="s2" next="stepC" />
    <step id="stepC" parent="s3" />
</job>

Read the documentation to gain deeper knowledge on these topics: http://docs.spring.io/spring-batch/reference/html/configureStep.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top