title: Using FlatFileItemReader with a TaskExecutor (Thread Safety)
body: <p>There are a lot of examples which use <code>FlatFileItemReader</code> along with <code>TaskExecutor</code>. I provide samples below (both with XML and Java Config):</p>
  
  <ul>
  <li><a href="http://www.oracle.com/technetwork/articles/cloudcomp/coherence-springbatch-1400985.html" rel="nofollow noreferrer">Using Oracle Coherence with Spring Batch</a></li>
  <li><a href="https://examples.javacodegeeks.com/enterprise-java/spring/batch/spring-batch-multithreading-example/" rel="nofollow noreferrer">Spring Batch Multithreading Example</a></li>
  </ul>
  
  <p>I have used it my self with XML configuration for large CSVs (GB size) writing to database with the out-of-the-box <code>JpaItemWriter</code>. There seem to be no issues even without setting save-state = false or taking any kind of special handling.</p>
  
  <p>Now, <code>FlatFileItemReader</code> is documented <strong>as not thread-safe</strong>. </p>
  
  <p>My guess was that <code>JpaItemWriter</code> was "covering" the issue by persisting Sets i.e. collections with no duplicates if the <code>hashCode()</code> and <code>equals()</code> were covering the business key of the Entity. However, even this way it is not enough to prevent duplicates due to non-thread safe reading and processing.</p>
  
  <p>Could you please clarify: is it proper/correct/safe to use the out-of-the-box <code>FlatFileItemReader</code> within a Tasklet which has assigned a TaskExecutor? Regardless of the Writer. If not, how could we explain in theory the lack of errors when a <code>JPAItemWriter</code> is used?</p>
  
  <p>P.S: The example links that I give above, use <code>FlatFileItemReader</code> with TaskExecutor without mentioning at all possible thread-safety issues... </p>