Java Reference
In-Depth Information
Configuring the Number of Restarts
There can be situations where a job doesn't run successfully for some reason outside of your control. Say
for example that the job downloads a file from a web site as one of its steps, and the web site is down. If
the download fails the first time, it may work if you try again in 10 minutes. However, you probably don't
want to try that download indefinitely. Because of this, you may want to configure the job so it can be
executed only five times. After the fifth time, it can't be rerun any more.
Spring Batch provides this facility at the step level instead of the job level. Again, looking at the
transactionJob example, if you only want to attempt to import an input file twice, you modify the step
configuration as in Listing 6-38.
Listing 6-38. Allowing the File Import to Be Attempted Only Once
<step id="importTransactionFileStep">
<tasklet start-limit="2">
<chunk reader="transactionFileReader" writer="transactionWriter"
<stream ref="fileItemReader"/>
<listener ref="transactionFileReader"/>
In this case, if you attempt to restart this job more than once, because the start-limit attribute has
been configured to 2 , you can't reexecute this job. The initial run takes up one attempt you're allowed
allowing you one other try. You receive an
org.springframework.batch.core.StartLimitExceededException , as shown in Listing 6-39, if you attempt
to execute the job again.
Listing 6-39. Results from Reexecuting transactionJob More Than Once
2011-01-13 20:10:05,127 ERROR
[org.springframework.batch.core.job.AbstractJob] - <Encountered fatal error
executing job>
org.springframework.batch.core.JobExecutionException: Flow execution ended
at org.springframework.batch.core.job.flow.FlowJob.doExecute(
at org.springframework.batch.core.job.AbstractJob.execute(
at org.springframework.core.task.SyncTaskExecutor.execute(
Search WWH ::

Custom Search