TERASOLUNA Batch Framework for Java (5.x) Development Guideline - version 5.1.1.RELEASE, 2018-3-16
> INDEX

Here, how to distinguish between chunk model and tasklet model is explained by organizing each feature. In the explanation, there are matters to be described in detail in the subsequent chapters, so please refer to corresponding chapters as appropriate.

Following contents should be viewed as examples for the concepts, and not as constraints or recommendations. Refer to it while creating a job depending on the characteristics of the users and systems.

The main differences between the chunk model and the tasklet model are given below.

Comparison of chunk model and tasklet model.
Item Chunk Tasklet

Components

It consists of 3 components mainly ItemReader, ItemProcessor and ItemWriter.

It is consolidated in one Tasklet.

Transaction

A certain number of records are processed by issuing intermediate commit. Batch commit cannot be done.
It can be processed by specific machine resources regardless of the data count.
If an error occurs during the process, unprocessed data and processed data get mixed.

It is basic to process at once in batch commit. There is a need for the user to implement intermediate commits.
If the data to be processed is large, machine resources may get exhausted.
If an error occurs during the process, only the unprocessed data is rolled back.

Restart

It can be restarted based on the record count.

It cannot be restarted based on the record count.

Based on this, we will introduce some examples of using each one as follows.

To make recovery as simple as possible

When the job, having error, is to be recovered by only re-running the target job, tasklet model can be chosen to make recovery simple.
In chunk model, it should be dealt by returning the processed data to the state before executing the job and by creating a job to process only the unprocessed data.

To consolidate the process contents

When you want to prioritize the outlook of job such as one job in one class, tasklet can be chosen.

To process large data stably

For example when performing batch process of 10 million records, consider to use chunk model when the targeting number of cases affects the resources. It means stabilizing the process by intermediate commit. Even in tasklet model, intermediate commit can be used, but it is simpler to implement in chunk model.

To restart based on the record count for the recovery after error

When batch window is severe and you want to resume from erroneous data onwards, chunk model should be chosen to use restart based on the record count provided by Spring Batch. This eliminates the need to create that mechanism for each job.

Chunk model and tasklet model are basically used in combination.
It is not necessary to implement only one model in all jobs in the batch system.
It is natural to use one model as the basis and the other model depending on the situation, based on the characteristics of the job of the entire system.

For example, in most cases it is natural to choose a tasklet model as the basis for processing number and processing time, and in a very small number of cases, choosing a chunk model for jobs that process large numbers of records.

TERASOLUNA Batch Framework for Java (5.x) Development Guideline - version 5.1.1.RELEASE, 2018-3-16