Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Step, Tasklet and Chunk in Spring Batch [closed]

What is the difference between Step, Tasklet and Chunk in spring batch.?

Also, How to execute step in parallel via Spring Batch. ?

like image 401
Priyanka Mokashi Avatar asked Oct 14 '16 10:10

Priyanka Mokashi


People also ask

Is it possible to create a tasklet in Spring Batch?

In spring batch, you'll mostly do chunk oriented processing: with a reader, a processor, and a writer. From the official documentation: But you can make your own tasklet, and set it in your step. For example, a tasklet that executes a SQL query. (example here: Tasklet to delete a table in spring batch )

How to do chunk oriented processing in Spring Batch?

In spring batch, you'll mostly do chunk oriented processing: with a reader, a processor, and a writer. From the official documentation: Chunk oriented processing refers to reading the data one at a time, and creating 'chunks' that will be written out, within a transaction boundary But you can make your own tasklet, and set it in your step.

What is done in a Spring Batch step?

What is done in the Step is represented by a tasklet, they do the task. In spring batch, you'll mostly do chunk oriented processing: with a reader, a processor, and a writer. From the official documentation: But you can make your own tasklet, and set it in your step.

What is a chunk-oriented processing tasklet?

For example, a tasklet that executes a SQL query. (example here: Tasklet to delete a table in spring batch ) So, the steps are ordered in a job, each step contains a tasklet, which does a task. One of those tasklet (and probably the most used one) is the chunk oriented processing tasklet.


1 Answers

Well that's actually a good question. Here's an example of configuration:

<job id="sampleJob" job-repository="jobRepository">     <step id="step1" next="step2">         <tasklet transaction-manager="transactionManager">             <chunk reader="itemReader" writer="itemWriter" commit-interval="10"/>         </tasklet>     </step>     <step id="step2">          <tasklet ref="myTasklet"/>     </step> </job> 

You have a Job, this job is made of steps. Most of the time, these steps are successive. You define in what order your work must be done with steps: you do step 1, then step 2, then step 3, you can do step 4 if step 3 failed, or go directly to step 5, etc.

What is done in the Step is represented by a tasklet, they do the task.

In spring batch, you'll mostly do chunk oriented processing: with a reader, a processor, and a writer. From the official documentation:

Chunk oriented processing refers to reading the data one at a time, and creating 'chunks' that will be written out, within a transaction boundary

But you can make your own tasklet, and set it in your step. For example, a tasklet that executes a SQL query. (example here: Tasklet to delete a table in spring batch )

So, the steps are ordered in a job, each step contains a tasklet, which does a task. One of those tasklet (and probably the most used one) is the chunk oriented processing tasklet.

If you're curious, here is the ChunkOrientedTasklet's doc. As you can see, it implements the Tasklet interface.

For more information: http://docs.spring.io/spring-batch/reference/html/configureStep.html

And yes, spring batch is well made for parrallel processing, using flows: http://docs.spring.io/spring-batch/reference/html/scalability.html

like image 91
Asoub Avatar answered Sep 19 '22 13:09

Asoub