How to terminate Step within a Spring Batch Split Flow with a Decider

spring-batch

Solution

Given no answers from anyone on this, I'll proffer the hack that I'm using. It's not pretty, but neither is Spring.

Create a No Op Tasklet to use in a No Op step.

public class NoopTasklet implements Tasklet {
    @Override
    public RepeatStatus execute(final StepContribution contribution,
            final ChunkContext chunkContext) throws Exception {
        return RepeatStatus.FINISHED;
    }
}

The add NOOP tasklet to the decision block from the original example

<!-- Does nothing -->
<bean id="noopTasklet" class="com.foo.NoopTasklet" />

<!-- From example in question
<decision id="decideToRunStep04" decider="isStepNeededDecider" >
    <next on="RUN" to="step04"/>
    <next on="SKIP" to="noop01"/>
</decision>
<step id="step04">
    <!-- Conditionally do something-->
</step>
<step id="noop01">
    <!-- Does nothing in the SKIP case
    <tasklet ref="noopTasklet" />
</step>

Problem

I've happened up the following design defect in Spring Batch. - A Step must have a Next attribute unless it is the last Step or last Step of a Split Flow. - A Decider block must handle all cases returned by the Decider. Because of this, in a Split Flow, where the final Step would not have a Next attribute, if there is a Decider guarding it, then it must have a Next attribute. So it shouldn't have that attribute, but it also needs it. Catch 22. Example: ``` <!-- Process parallel steps --> <split id="split01"> <flow> <step id="step1" next="step02"> <!-- Do something --> </step> <step id="step02"> <!-- Do something else --> </step> </flow> <flow> <step id="step03"> <!-- Do something --> </step> <!-- Only run under specific conditions --> <decision id="decideToRunStep04" decider="isStepNeededDecider" > <next on="RUN" to="step04"/> <!-- Other state is "SKIP" --> </decision> <step id="step04"> <!-- Conditionally do something--> </step> </flow> </split> <step id="step05" > <!-- Some more stuff --> </step> ``` This seems like something the Spring guys would have thought of, so curious what the right, non-hack way to achieve this is. Thanks.

Original source

Related problems