Java Reference
In-Depth Information
2011-01-11 20:08:04,727 INFO
[] - <Job:
[FlowJob: [name=transactionJob]] completed with the following parameters:
[{transactionFile=/Users/mminella/Dropbox/Spring Batch
Book/Content/Code/Chapter 6/transactionFile.txt,
summaryFile=/Users/mminella/Dropbox/Spring Batch Book/Content/Code/Chapter
6/accountSummary15.csv}] and the following status: [STOPPED]>
Stopping a job programmatically is an important tool when you're designing batch jobs.
Unfortunately, not all batch jobs are perfect, and you sometimes need to shut down a job when it's
running. The next section discusses the ways you can stop a Spring Batch job without doing a kill -9 on
the process.
External Stoppage
There aren't many worse feelings. You've done your homework. You've run your tests, and all looks
good. You start the job, which you know will take hours to complete. Only a couple of minutes later, you
realize that you made a mistake and you need to stop the job—but you can't just kill it. You need it to
end gracefully so your database and processing are left in a state that can be restarted. Luckily for you,
the authors of Spring Batch have gone through your pain and have developed a couple of ways to stop
an already running job. The two you look at here are using Spring Batch Admin and
CommandLineJobRunner . Let's start with Spring Batch Admin.
Stopping via Spring Batch Admin
Having an instance of Spring Batch Admin pointed at your JobRepository is by far the easiest way to stop
jobs. To see this in action, start the transactionJob job with a large transaction file (100 records in this
case). With the job running, if you go to the page for the job's execution, as shown in Figure 6-9, you see
a Stop button in the upper-left corner.
Search WWH ::

Custom Search