Class AsyncItemProcessor<I,O>

java.lang.Object
org.springframework.batch.integration.async.AsyncItemProcessor<I,O>
Type Parameters:
I - the input object type
O - the output object type (will be wrapped in a Future)
All Implemented Interfaces:
org.springframework.batch.infrastructure.item.ItemProcessor<I, Future<O>>

public class AsyncItemProcessor<I,O> extends Object implements org.springframework.batch.infrastructure.item.ItemProcessor<I, Future<O>>
An ItemProcessor that delegates to a nested processor and in the background. To allow for background processing the return value from the processor is a Future which needs to be unpacked before the item can be used by a client.

Because the Future is typically unwrapped in the ItemWriter, there are lifecycle and stats limitations (since the framework doesn't know what the result of the processor is). While not an exhaustive list, things like StepExecution.getFilterCount() will not reflect the number of filtered items and ItemProcessListener.onProcessError(Object, Exception) will not be called.

Author:
Dave Syer, Mahmoud Ben Hassine
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    AsyncItemProcessor(org.springframework.batch.infrastructure.item.ItemProcessor<I,O> delegate)
    Create a new AsyncItemProcessor with the delegate ItemProcessor.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Future<O>
    process(I item)
    Transform the input by delegating to the provided item processor.
    void
    setDelegate(org.springframework.batch.infrastructure.item.ItemProcessor<I,O> delegate)
    The ItemProcessor to use to delegate processing to in a background thread.
    void
    setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
    The TaskExecutor to use to allow the item processing to proceed in the background.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AsyncItemProcessor

      public AsyncItemProcessor(org.springframework.batch.infrastructure.item.ItemProcessor<I,O> delegate)
      Create a new AsyncItemProcessor with the delegate ItemProcessor.
      Parameters:
      delegate - the ItemProcessor to use as a delegate
      Since:
      6.0
  • Method Details

    • setDelegate

      public void setDelegate(org.springframework.batch.infrastructure.item.ItemProcessor<I,O> delegate)
      The ItemProcessor to use to delegate processing to in a background thread.
      Parameters:
      delegate - the ItemProcessor to use as a delegate
    • setTaskExecutor

      public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
      The TaskExecutor to use to allow the item processing to proceed in the background. Defaults to a SyncTaskExecutor so no threads are created unless this is overridden.
      Parameters:
      taskExecutor - a TaskExecutor
    • process

      public @Nullable Future<O> process(I item) throws Exception
      Transform the input by delegating to the provided item processor. The return value is wrapped in a Future so that clients can unpack it later.
      Specified by:
      process in interface org.springframework.batch.infrastructure.item.ItemProcessor<I,O>
      Throws:
      Exception
      See Also:
      • ItemProcessor.process(Object)