Java Reference
In-Depth Information
package com.apress.springenterpriserecipes.springbatch.solution2;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
public class HoroscopeDecider implements JobExecutionDecider {
private boolean isMercuryIsInRetrograde (){ return Math.random() > .9 ; }
public FlowExecutionStatus decide(JobExecution jobExecution,
StepExecution stepExecution) {
if (isMercuryIsInRetrograde()) {
return new FlowExecutionStatus("MERCURY_IN_RETROGRADE");
return FlowExecutionStatus.COMPLETED;
All that remains is the XML configuration:
<beans:bean id="horoscopeDecider"class="com.apress.springenterpriserecipes.
<job id="job">
<step id="step1" next="decision" ><!-- ... --></step>
<decision id="decision" decider="horoscopeDecider">
<next on="MERCURY_IN_RETROGRADE" to="step2" />
<next on="COMPLETED" to="step3" />
<step id="step2" next="step3"> <!-- ... --> </step>
<step id="step3" parent="s3"> <!-- ... --> </step>
9-10. Parameterizing a Job
The previous examples work well enough, but they leave something to be desired in terms of flexibility.
To apply the batch code to some other file, you'd have to edit the configuration and hard-code the name
in there.
Use JobParameters to parameterize a job , which is then available to your step s through Spring Batch's
expression language or via API calls.
Search WWH ::

Custom Search