Java Reference
In-Depth Information
Figure 6-8. Results of the second run of transactionJob
Using the <stop> tag along with configuring the ability to reexecute steps in the job is a useful way to
allow for issues to be fixed based on checks in the execution of a job. In the next section, you refactor the
listener to use the StepExecution.setTerminateOnly() method to communicate to Spring Batch to end
the job.
Stopping with StepExecution
In the transactionJob example, you manually handled stopping the job by using the ExitStatus of a
StepListener and the configured transitions in the job. Although this approach works, it requires you to
specially configure the job's transitions and override the step's ExitStatus .
There is a slightly cleaner approach. In the StepListener, you have access to the StepExecution. With
this, as you see in Listing 6-30, you can call the StepExecution.setTerminateOnly() method. This method
sets a flag that tells Spring Batch to end after the step is complete.
Listing 6-30. TransactionReader with setTerminateOnly() Call
package com.apress.springbatch.chapter6;
 
Search WWH ::




Custom Search