Back to Summer Batch home page

The batch mechanisms

Most of the typical batch processing is being made through chunk oriented steps usage, which are implementing a read/process/write repetitive pattern on data.

Typical chunk oriented step behaviour

A chunk oriented step is made of -- in that order -- :

  • An Item Reader
  • An optional Item Processor
  • An Item Writer

The data to be processed is split into chunks whose size can be optionally defined by using the item-count attribute (= chunk size);

Each chunk is holding its own transaction. The transactional behaviour of the chunk oriented step is demonstrated by the figure below:

Figure 3.1. Chunk oriented step : basic transactional behaviour

Chunk oriented step : basic transactional behaviour

This is the basic behaviour, when everything runs smoothly and the step completes gracefully. The Read/Process/Write pattern is running within the transaction boundaries.

Each time a transaction is commited, the job repository is being updated, in order to guarantee a potential job restartability (provided the repository update is being done on a persistent storage).

Now, what if something goes wrong ?

ANY uncaught exception that is thrown during either Read or Process or Write operation will lead to rollback the current chunk transaction; this will cause the step to FAIL, and consequently, the job to FAIL. If the job restartability has been set up, the job repository will be updated on the transaction rollback, so that the job can be restarted at a later time.

The figure below illustrates that mechanism

Figure 3.2. Chunk oriented step : when the transaction rollback occurs

Chunk oriented step : when the transaction rollback occurs

When for any reason we leave the step (either because it completed or failed because of an unexpected exception), the job repository is updated; this update uses a transaction of its own, clearly separated of any chunk related transaction.

The tasklet approach

Using the Chunk oriented step is not the only option; one can use a tasklet (aka a batchlet) to cover a whole step. A batchlet is a class that implements the Summer.Batch.Core.Step.Tasklet.ITasklet interface.

The transactional support is guaranted by the Summer.Batch.Core.Step.Tasklet.TaskletStep class, that is in charge of executing the batchlet code (see the DoExecute method, that delegates to the DoInTransaction method, that wraps the tasklet code effective execution (the Execute method implementation) ).

Back to Summer Batch home page