Java Reference
In-Depth Information
Yet when you think about batch jobs, you're really talking about a collection of actions. The term
flow 1 is a good way to describe a job. Using the web application example again, think about how the
checkout process of a shopping cart application works. When you click Check Out with items in your
cart, you're walked through a series of steps: register or sign in, confirm shipping address, enter billing
information, confirm order, submit order. This flow is similar to what a job is.
For the purpose of this topic, a job is defined as a unique, ordered list of steps that can be executed
from start to finish independently. Let's break down this definition so you can get a better
understanding of what you're working with:
Unique: Jobs in Spring Batch are configured via XML similar to how beans are
configured using the core Spring framework and are reusable as a result. You can
execute a job as many times as you need to with the same configuration. Because
of this there is no reason to define the same job multiple times.
Ordered list of steps: 2 Going back to the checkout flow example, the order of the
steps matter. You can't validate your shipping address if you haven't registered
one in the first place. You can't execute the checkout process if your shopping cart
is empty. The order of steps in your job is important. You can't generate a
customer's statement until their transactions have been imported into your
system. You can't calculate the balance of an account until you've calculated all of
your fees. You structure jobs in a sequence that allows all steps to be executed in a
logical order.
Can be executed from start to finish: Chapter 1 defined a batch process as a process
that can run without additional interaction to some form of completion. A job is a
series of steps that can be executed without external dependencies. You don't
structure a job so that the third step is to wait until a file is sent to a directory to be
processed. Instead, you have a job begin when the file has arrived.
Independently : Each batch job should be able to execute without external
dependencies affecting it. This doesn't mean a job can't have dependencies. On
the contrary, there are not many practical jobs (except “Hello, World”) that don't
have external dependencies. However, the job should be able to manage those
dependencies. If a file isn't there, it handles the error gracefully. It doesn't wait for
a file to be delivered (that's the responsibility of a scheduler, and so on). A job can
handle all elements of the process it's defined to do.
As a comparison, Figure 4-2 shows how a batch process executes versus the web application in
Figure 4-1.
1 For those familiar with the Spring Web Flow framework, a job is very similar in structure to a flow
within a web application.
2 Although most jobs consist of an ordered list of steps, Spring Batch does support the ability to execute
steps in parallel. This feature is discussed later.
Search WWH ::

Custom Search