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
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
1 2 3 4 5 6 7 |
package org.springframework.batch.core.launch; public interface JobLauncher { public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException; } |
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
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
1 2 3 4 5 6 7 |
package org.springframework.batch.item; public interface ItemReader<T>{ T read() throws Exception, UnexpectedInputException, ParseException,NonTransientResourceException; } |
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
1 2 3 4 5 6 7 |
package org.springframework.batch.item; public interface ItemWriter<T>{ void write(List<? extends T> items) throws Exception; } |
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: 25939
Tomcy John
Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Thanks for sharing the information but what’s the difference between CursorItemReader’s setFetchSize() and PagingItemReader’s setPageSize()? isn’t it the same?
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