img
.
Table 20-3. Job Execution Policies
Policy
Description
Skip failed records
It's possible to instruct Spring Batch to "skip" those problematic
records (for example, one record doesn't pass validation), instead of
rejecting the entire chunk of records or file.
Retry on error
Spring Batch supports retry policy when error occurs. For example, an
item-processing step can retry a number of times (it may need to
invoke some kind of external web service call to validate the data, but
under heavy loading, the external service may not respond within a
certain time occasionally) before it fails.
Multi-thread Step Processing
A step can be configured to run in a multithreaded environment to
improve performance.
Parallel processing
Steps within a job can configure for parallel execution to further boost
the performance.
Step Partitioning
Spring Batch provides an SPI that support the partitioning of a step. In
this case, the step is called the master, while the partitioned steps are
called the slaves. The slave steps can be executed either by local threads
or remotely for better performance.
Remote chunking
In Spring Batch, it's possible to delegate chunk processing to multiple
machines. For example, the master machine can perform the read
process, while multiple slave machines perform chunk-based writing of
data (via the ChunkProvider<T> interface). This provides a very flexible
horizontal scaling solution for batch job execution.
Implementing a Batch Job
Let's see Spring Batch in action by implementing a simple batch job. In the contact application we
developed in Chapter 18, each contact contains basic information including the first name, last name,
and date of birth. In addition, each contact associates with zero or more hobbies. The backend for
basic CRUD operations is already available after importing the sample project mentioned earlier in
this chapter.
In this section, we will implement a batch job for importing contact information from an XML file
into the database. Castor (http://castor.codehaus.org) will be used as the XML marshaller and
unmarshaller.
In the following sections, we will go through the processing of implementing the batch job. Steps
including the required dependencies, batch job configuration, file format, and so on, will be covered.
Adding Required Dependencies
First we need to add the dependencies for Spring Batch and Castor into the project, as shown in Table
20-4.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home