Class SynchronizedItemReader<T>

java.lang.Object
org.springframework.batch.item.support.SynchronizedItemReader<T>
Type Parameters:
T - type of objects to read
All Implemented Interfaces:
ItemReader<T>

public class SynchronizedItemReader<T> extends Object implements ItemReader<T>
This is an ItemReader decorator with a synchronized ItemReader.read() method. This decorator is useful when using a non thread-safe item reader in a multi-threaded step.
Since:
5.1.0
Author:
Mahmoud Ben Hassine
  • Constructor Details

    • SynchronizedItemReader

      public SynchronizedItemReader(ItemReader<T> delegate)
  • Method Details

    • read

      @Nullable public T read() throws Exception
      This method delegates to the read method of the delegate and is synchronized with a lock.
      Specified by:
      read in interface ItemReader<T>
      Returns:
      T the item to be processed or null if the data source is exhausted
      Throws:
      ParseException - if there is a problem parsing the current record (but the next one may still be valid)
      NonTransientResourceException - if there is a fatal exception in the underlying resource. After throwing this exception implementations should endeavour to return null from subsequent calls to read.
      UnexpectedInputException - if there is an uncategorised problem with the input data. Assume potentially transient, so subsequent calls to read might succeed.
      Exception - if an there is a non-specific error.