Java Reference
In-Depth Information
Like the job, represents the step as
configured in the XML as well as
provides the ability to execute a step.
A strategy interface that provides the
ability to input items.
A facility to apply business logic to an
individual item as provided.
A strategy interface that provides the
ability to output a list of items.
One of the advantages of the way Spring has structured a job is that it decouples each step into its
own independent processor. Each step is responsible for obtaining its own data, applying the required
business logic to it, and then writing the data to the appropriate location. This decoupling provides a
number of features:
Flexibility: The ability to alter the order of processing with nothing more than an
XML change is something many frameworks talk about yet very few deliver. Spring
Batch is one that does deliver. Thinking about the earlier bank account example.,
If you wanted to apply the debits before the credits, the only change required
would be to reorder the steps in the job XML (Chapter 4 shows an example). You
can also skip a step, execute a step conditionally based on the results of a previous
step, or even run multiple steps in parallel by doing nothing more than tweaking
the XML.
Maintainability: With the code for each step decoupled from the steps before and
after it, steps are easy to unit-test, debug, and update with virtually no impact on
other steps. Decoupled steps also make it possible to reuse steps in multiple jobs.
As you'll see in upcoming chapters, steps are nothing more than Spring beans and
can be reused just like any other bean in Spring.
Scalability: Decoupling steps in a job provides a number of options to scale your
jobs. You can execute steps in parallel. You can divide the work within a step
across threads and execute the code of a single step in parallel (you see a bit more
about this later in the chapter). Any of these abilities lets you meet the scalability
needs of your business with minimum direct impact on your code.
Reliability: By decoupling each step and each piece within a step, you can
structure jobs such that they can be restarted at a given point in the process. If a
job fails after processing 50,000 records out of 10 million in step 3 out of 7, you can
restart it right where it left off.
Job Execution
Let's look at what happens with the components and their relationships when a job is run. Notice in
Figure 2-2 that the piece most of the components share is JobRepository. This is a datastore (in memory
or a database) that is used to persist information about the job and step executions. A JobExecution or
Search WWH ::

Custom Search