Java Reference
In-Depth Information
Solution
There are different ways to change the runtime profile of your
job
s, mainly by exerting control over the
way
step
s are executed: concurrent
step
s, decisions, and sequential
step
s.
How It Works
Thus far, you have explored running one
step
in a
job
. Typical
job
s of almost any complexity will have
multiple
step
s, however. A
step
provides a boundary (transactional or not) to the beans/logic it encloses.
A
step
can have its own
reader
,
writer
, and
processor
. Each
step
helps decide what the next step will
be. A
step
is isolated and provides focused functionality that can be assembled using the updated
schema and configuration options in Spring Batch 2.0 in very sophisticated workflows. In fact, some of
the concepts and patterns you're about to see will be very familiar if you have an interest in business
process management (BPM) systems and workflows. (To learn more about BPM, and jBPM in particular,
see Chapter 11.) BPM provides many constructs for process or job control that are similar to what you're
seeing here.
A
step
often corresponds to a bullet point when you outline the definition of a
job
on paper. For
example, a batch job to load the daily sales and produce a report might be proposed as follows:
Daily Sales Report Job
1.
Load customers from the CSV file into the database.
2.
Calculate daily statistics and write to a report file.
3.
Send messages to the message queue to notify an external system of the
successful registration for each of the newly loaded customers.
Sequential Steps
In the previous example, there's an implied sequence between the first two
step
s: the audit file can't be
written until all the registrations have completed. This sort of relationship is the default relationship
between two
step
s. One occurs after the other. Each
step
executes with its own execution context and
shares only a parent
job
execution context and an order.
<job id="nightlyRegistrationsJob"
job-repository="jobRepository">
<step id="loadRegistrations" next="reportStatistics" >
<tasklet ref = "tasklet1"/>
</step>
<step id="reportStatistics" next="…" >
<tasklet ref ="tasklet2"/>
</step>
<!-- … other steps … -->
</job>
Notice that you specify the next attribute on the
step
elements to tell processing which
step
to
go to next.
Concurrency
The first version of Spring Batch was oriented toward batch processing inside the same thread and, with
some alteration, perhaps inside the virtual machine. There were workarounds, of course, but the
situation was less than ideal.
Search WWH ::
Custom Search