Class ChunkTaskExecutorItemWriter<T>

java.lang.Object
org.springframework.batch.integration.chunk.ChunkTaskExecutorItemWriter<T>
Type Parameters:
T - type of items
All Implemented Interfaces:
StepExecutionListener, StepListener, ItemWriter<T>

public class ChunkTaskExecutorItemWriter<T> extends Object implements ItemWriter<T>, StepExecutionListener
Similar to ChunkMessageChannelItemWriter, this item writer submits chunk requests to local workers from a TaskExecutor instead of sending them over a message channel to remote workers.

The aggregation of worker contributions is done in the afterStep method, which waits for all worker responses and updates the step execution accordingly. If any worker response indicates a failure, the step execution is marked as failed and the exception is added to the step execution's failure exceptions. Otherwise, the step execution is marked as completed and the write counts and skip counts from all worker contributions are aggregated into the step execution's write count and write skip count. The commit count is also incremented for each successful worker contribution, while the rollback count is incremented for each failed worker contribution.

It should be noted that transaction management of the chunk as well as fault tolerance features are not handled by this item writer and are the responsibility of the delegate chunk processor.

Moreover, the lifecycle of the task executor is not handled by this item writer.

Since:
6.0
Author:
Mahmoud Ben Hassine
See Also:
  • Constructor Details

    • ChunkTaskExecutorItemWriter

      public ChunkTaskExecutorItemWriter(ChunkProcessor<T> chunkRequestProcessor, org.springframework.core.task.TaskExecutor taskExecutor)
      Parameters:
      chunkRequestProcessor - the chunk processor to process chunks
      taskExecutor - the task executor to submit chunk processing tasks to
  • Method Details

    • write

      public void write(Chunk<? extends T> chunk)
      Description copied from interface: ItemWriter
      Process the supplied data element. Will not be called with any null items in normal operation but might be called with an empty chunk, for example when all items have been filtered by an ItemProcessor or skipped by the fault-tolerant step processing. Implementations are expected to handle empty chunks gracefully.
      Specified by:
      write in interface ItemWriter<T>
      Parameters:
      chunk - of items to be written. Never null but may be empty.
    • beforeStep

      public void beforeStep(StepExecution stepExecution)
      Description copied from interface: StepExecutionListener
      Initialize the state of the listener with the StepExecution from the current scope.
      Specified by:
      beforeStep in interface StepExecutionListener
      Parameters:
      stepExecution - instance of StepExecution.
    • afterStep

      public ExitStatus afterStep(StepExecution stepExecution)
      Description copied from interface: StepExecutionListener
      Give a listener a chance to modify the exit status from a step. The value returned is combined with the normal exit status by using ExitStatus.and(ExitStatus).

      Called after execution of the step's processing logic (whether successful or failed). Throwing an exception in this method has no effect, as it is only logged.

      Specified by:
      afterStep in interface StepExecutionListener
      Parameters:
      stepExecution - a StepExecution instance.
      Returns:
      an ExitStatus to combine with the normal value. Return null (the default) to leave the old value unchanged.