Spring Batch - Difference between Step, Tasklet and Chunk | JavaInUse

Spring Batch - Difference between Step, Chunk and Tasklet

Spring Batch - Table Of Contents

Spring Batch Hello World example-Write data from csv to xml file Spring Boot Batch Simple example Spring Batch - Difference between Step, Chunk and Tasklet Spring Batch Tasklet - Hello World example Spring Boot + Batch + Task Scheduler Example

A Step is a domain object that encapsulates an independent, sequential phase of a batch job and contains all of the information necessary to define and control the actual batch processing.

Steps can be processed in either of the following two ways.
  • Chunk
  • Tasklet
Parameter Tasklet Chunk
When to use Suppose the job to be run a single granular task then Tasklet processing is used. Suppose the job to be run is complex and involves executing of tasks involving reads, processing and writes the we use chunk oriented processing
How it works No aggregation, just the task gets executed. It involves reading an input, processing it based on the business logic and then aggregating it till the commit-interval is reached and finally writing out the chunk of data output to a file or database table.
Usage Its not used commonly. Its the most common way of executing a Step.
Use Case Usually Used in scenarios invloving a single task like deleting a resource or executing a query . Usually used in scenarios where multiple aggregated steps need to be run like copying, processing and transferring of data .
Example <job id="taskletJob"> <step id="callingStoredProc"> <tasklet ref="callProc"/> </step> </job>
Spring Batch Tasklet Example
<job id="sampleJob" job-repository="jobRepository"> <step id="step1"> <tasklet transaction-manager="transactionManager"> <chunk reader="itemReader" writer="itemWriter" commit-interval="10"/> </tasklet> </step> </job>
Spring Batch Chunk Processing Example

See Also

Spring Batch Main Menu