Java Reference
In-Depth Information
<decision decider="decider" id="decision">
<next on="*" to="step2a"/>
<next on="FAILED" to="step2b"/>
<step id="step2a">
<tasklet ref="successTasklet"/>
<step id="step2b">
<tasklet ref="failTasklet"/>
Because you now know how to direct your processing from step to step either sequentially or via
logic, you won't always want to just go to another step. You may want to end or pause the job. The next
section covers how to handle those scenarios.
Ending a Job
You learned earlier that a JobInstance can't be executed more than once to a successful completion and
that a JobInstance is identified by the job name and the parameters passed into it. Because of this, you
need to be aware of the state in which you end your job if you do it programmatically. In reality, there
are three states in which you can programmatically end a job in Spring Batch:
Completed: This end state tells Spring Batch that processing has ended in a
successful way. When a JobInstance is completed, it isn't allowed to be rerun
with the same parameters.
Failed: In this case, the job hasn't run successfully to completion. Spring Batch
allows a job in the failed state to be rerun with the same parameters.
Stopped: In the stopped state, the job can be restarted. The interesting part
about a job that is stopped is that the job can be restarted from where it left off,
although no error has occurred. This state is very useful in scenarios when
human intervention or some other check or handling is required between steps.
It's important to note that these states are identified by Spring Batch evaluating the ExitStatus of
the step to determine what BatchStatus to persist in the JobRepository . ExitStatus can be returned from
a step, chunk, or job. BatchStatus is maintained in StepExecution or JobExecution and persisted in the
JobRepository . Let's begin looking at how to end the job in each state with the completed state.
To configure a job to end in the completed state based on the exit status of a step, you use the end
tag. In this state, you can't execute the same job again with the same parameters. Listing 4-43 shows that
the end tag has a single attribute that declares the ExitStatus value that triggers the job to end.
Listing 4-43. Ending a Job in the Completed State
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=""
Search WWH ::

Custom Search