title: <Spring Batch> Why does making ItemReader thread-safe leads us to loosing restartability?
body: <p>I have a multi-threaded batch job reading from a DB and I am concerned about different threads re-reading records as ItemReader is not thread safe in Spring batch. I went through <a href="http://docs.spring.io/spring-batch/faq.html" rel="nofollow">SpringBatch FAQ</a> section which states that </p>
  
  <blockquote>
    <p>You can synchronize the read() method (e.g. by wrapping it in a delegator that does the synchronization). Remember that you will lose restartability, so best practice is to mark the step as not restartable and to be safe (and efficient) you can also set saveState=false on the reader.</p>
  </blockquote>
  
  <p>I want to know why will I loose re-startability in this case? What has restartability got to do with synchronizing my read operations? It can always try again,right?
  Also, will this piece of code be enough for synchronizing the reader? </p>
  
  <pre><code>  public SynchronizedItemReader&lt;T&gt; implements ItemReader&lt;T&gt; {
    private final ItemReader&lt;T&gt; delegate; 
    public SynchronizedItemReader(ItemReader&lt;T&gt; delegate) {
      this.delegate = delegate;
    }
    public synchronized T read () {
      return delegate.read();
    }
  }
  </code></pre>