Spring Book – Chapter 21 – Spring Batch

Step

A Step is an independent process of a batch Job that contains all of the information necessary to define and control a particular phase in the job execution. A Job constitutes of multiple Step’s. Figure 23-6 below shows various instances constituting a Job and Step and also depicts its interaction in a pictorial manner.

 Figure 23-6. Instances constituting a Job and Step

Figure 23-6. Instances constituting a Job and Step

StepExecution

StepExecution is information about a single run of the step. Each execution has start time, stop time and status. Each execution can tell us how many items were processed, how many commits, rollbacks and skips.

JobRepository

It is the component to which all other components share and store information is called JobRepository. This is a data store that is used to persist information about the job and step executions.

JobLauncher

Simple interface for controlling jobs, including possible ad-hoc executions, based on different runtime identifiers. It is extremely important to note that this interface makes absolutely no guarantees about whether or not calls to it are executed synchronously or asynchronously. Listing 23-3 below shows the JobLauncher interface definition.

Listing 23-3. JobLauncher interface definition

Figure 23-7 below shows the functioning of the JobLauncher in a typical Spring Batch program.

 Figure 23-7. Functioning of a JobLauncher in Spring Batch

Figure 23-7. Functioning of a JobLauncher in Spring Batch

ItemReader

ItemReader is an abstraction that represents the retrieval of input for a Step, one item at a time. Implementations are expected to be stateful and will be called multiple times for each batch, with each call to read() returning a different value and finally returning null when all input data is exhausted. Listing 23-4 below shows the ItemReader interface definition.

Listing 23-4. ItemReader interface definition

ItemWriter

ItemWriter is similar in functionality to an ItemReader, but with inverse operations. ItemWriter is an abstraction that represents the output of a Step, one batch or chunk of items at a time. Class implementing this interface will be responsible for serializing objects as necessary. Generally, it is responsibility of implementing class to decide which technology to use for mapping and how it should be configured. Listing 23-5 below shows the ItemWriter interface definition.

Listing 23-5. ItemWriter interface definition

The write method is responsible for making sure that any internal buffers are flushed. If a transaction is active it will also usually be necessary to discard the output on a subsequent rollback. The resource to which the writer is sending data should normally be able to handle this itself.

Page Visitors: 24109

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

2 thoughts on “Spring Book – Chapter 21 – Spring Batch

  1. Thanks for sharing the information but what’s the difference between CursorItemReader’s setFetchSize() and PagingItemReader’s setPageSize()? isn’t it the same?

  2. Please provide an example for StoredProcedureItem Reader – which returns cursor and how to process cursor in processor – I am new to Spring Batch as part of my work I need to invoke Oracle Stored proc which takes one param as input and returns result set which I need to process in Spring Batch Processor.

    Thanks
    Laxmi

Leave a Reply

Your email address will not be published. Required fields are marked *