天天看點

Spring Batch Step 流程

– Start

點選此處觀看本系列配套視訊。

順序流程(Sequential Flow)

<job id="job">
    <step id="stepA" parent="s1" next="stepB" />
    <step id="stepB" parent="s2" next="stepC"/>
    <step id="stepC" parent="s3" />
</job>
           
Spring Batch Step 流程

條件流程(Conditional Flow)

<job id="job">
    <step id="stepA" parent="s1">
        <next on="*" to="stepB" />
        <next on="FAILED" to="stepC" />
    </step>
    <step id="stepB" parent="s2" next="stepC">
		<fail on="FAILED" exit-code="EARLY TERMINATION"/>
	</step>
    <step id="stepC" parent="s3">
		<stop on="COMPLETED"/>
		<end on="FAILED"/>
	</step>
</job>
           
Spring Batch Step 流程

自定義流程(Programmatic Flow Decisions)

首先,繼承 JobExecutionDecider,自定義流程.

public class MyDecider implements JobExecutionDecider {
    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
        if (someCondition) {
            return "FAILED";
        }
        else {
            return "COMPLETED";
        }
    }
}
           

然後就可以使用這個流程了。

<job id="job">
    <step id="step1" parent="s1" next="decision" />

    <decision id="decision" decider="decider">
        <next on="FAILED" to="step2" />
        <next on="COMPLETED" to="step3" />
    </decision>

    <step id="step2" parent="s2" next="step3"/>
    <step id="step3" parent="s3" />
</job>

<beans:bean id="decider" class="com.MyDecider"/>
           

并行流程(Split Flow)

<split id="split1" next="step4">
    <flow>
        <step id="step1" parent="s1" next="step2"/>
        <step id="step2" parent="s2"/>
    </flow>
    <flow>
        <step id="step3" parent="s3"/>
    </flow>
</split>
<step id="step4" parent="s4"/>
           

– 更多參見:Spring Batch 精萃

– 聲 明:轉載請注明出處

– Last Updated on 2017-07-24

– Written by ShangBo on 2017-07-24

– End