title: Spring Batch : Tasklet with multi threaded executor has very bad performances related to Throttling algorithm
body: <p>Using Spring batch 2.2.1, I have configured a Spring Batch Job, I used this approach:</p>
  
  <ul>
  <li><a href="http://static.springsource.org/spring-batch/reference/html/scalability.html#multithreadedStep" rel="noreferrer">http://static.springsource.org/spring-batch/reference/html/scalability.html#multithreadedStep</a></li>
  </ul>
  
  <p>Configuration is the following:</p>
  
  <ul>
  <li><p>Tasklet uses ThreadPoolTaskExecutor limited to 15 threads</p></li>
  <li><p>throttle-limit is equal to number of threads</p></li>
  <li><p>Chunk is used with:</p>
  
  <ul>
  <li><p>1 synchronized adapter of JdbcCursorItemReader to allow it's use by many threads as per Spring Batch documentation recommandation</p>
  
  <blockquote>
    <p>You can synchronize the call to read() and as long as the processing and writing is the most expensive part of the chunk your step may still complete much faster than in a single threaded configuration. </p>
  </blockquote></li>
  <li><p>saveState is false on JdbcCursorItemReader</p></li>
  <li><p>A Custom ItemWriter based on JPA. <strong>Note that its processing of one item can vary in terms of processing time, it can take few millis to few seconds ( > 60s).</strong></p></li>
  <li><p>commit-interval set to 1 (I know it could be better but it's not the issue)</p></li>
  </ul></li>
  <li><p>All jdbc pools are fine, regarding Spring Batch doc recommandation</p></li>
  </ul>
  
  <p><strong>Running the batch leads to very strange and bad results due to the following:</strong></p>
  
  <ul>
  <li>at some step, if the items take some time to process by a writer, nearly all threads in the thread pool end up doing nothing instead of processing, only the slow writer is working.</li>
  </ul>
  
  <p>Looking at Spring Batch code, root cause seems to be in this package:</p>
  
  <ul>
  <li>org/springframework/batch/repeat/support/</li>
  </ul>
  
  <p>Is this way of working a feature or is it a limitation/bug ?</p>
  
  <p>If it's a feature, what is the way by configuration to make all threads without being starved by long processing work without having to rewrite everything ?</p>
  
  <p>Note that if all items take the same time, everything works fine and multi-threading is OK, but if one of the item processing takes much more time, then multi-threading is nearly useless for the time the slow process works.</p>
  
  <p>Note I opened this issue:</p>
  
  <ul>
  <li><a href="https://jira.springsource.org/browse/BATCH-2081" rel="noreferrer">https://jira.springsource.org/browse/BATCH-2081</a></li>
  </ul>