title: thread executor doesn't work spring batch
body: <p>I have a treatment that lasts 9 minutes, I would like to reduce the execution time by using thread-executor. </p>
  
  <p>My reader reads 1200 lines in database and makes a UNPIVOT which gives me 56 036 lines to write in a csv file.</p>
  
  <p>I have tried several ways but no difference in time, I have the impression that the configuration is not taken into account.</p>
  
  <pre><code>@Bean
  @StepScope
  public ItemReader&lt;DmNebefPdhExportRetenuCSV&gt; datamartEffRetenuItemReader(
          @Value("#{jobParameters['dateExport']}") Date dateExport) throws Exception {
      PagingQueryProvider query = createEffRetenuQuery();
      Map&lt;String, Object&gt; parameters = new HashMap&lt;&gt;();
      parameters.put("dateExport", dateExport);
  
      JdbcPagingItemReader&lt;DmNebefPdhExportRetenuCSV&gt; reader = new JdbcPagingItemReader&lt;&gt;();
      reader.setDataSource(sdmDataSource);
      reader.setParameterValues(parameters);
      reader.setQueryProvider(query);
      reader.setFetchSize(1000);
      reader.setPageSize(1000);
      reader.setRowMapper(new BeanPropertyRowMapper&lt;&gt;(DmNebefPdhExportRetenuCSV.class));
  
      return reader;
  }
  
  @Bean
  @StepScope
  FlatFileItemWriter&lt;DmNebefPdhExportRetenuCSV&gt; exportEffRetenuItemWriter(
          @Value("#{jobParameters['dateExport']}") Date dateExport) {
      // Construction du Header
      StringHeaderWriter headerWriter = new StringHeaderWriter(EXPORT_EFF_RETENU_CSV_HEADER);
  
      String newExportFileVersion = getExportRetenuVersion(dateExport);
  
      // Nom du fichier d'export
      String csvFileName = createEffRetenuExportFileName(dateExport, newExportFileVersion);
  
      // Chemin complet d'enregistrement du fichier
      String exportFilePath = String.join("/", exportArchiveCreRetenuPath, csvFileName);
  
      // Définition du délimiteur et des champs à mapper
      LineAggregator&lt;DmNebefPdhExportRetenuCSV&gt; lineAggregator = effRetenuLineAggregator();
  
      // Put dans le context pour récupérer dans le listener
      exportEffRetenuJobListener.getJobExecution().getExecutionContext().put("exportFilePath", exportFilePath);
      exportEffRetenuJobListener.getJobExecution().getExecutionContext().put("csvFileName", csvFileName);
      exportEffRetenuJobListener.getJobExecution().getExecutionContext().put("newExportFileVersion",
              newExportFileVersion);
  
      FlatFileItemWriter&lt;DmNebefPdhExportRetenuCSV&gt; csvFileWriter = new FlatFileItemWriter&lt;&gt;();
      csvFileWriter.setShouldDeleteIfEmpty(true);
      csvFileWriter.setHeaderCallback(headerWriter);
      csvFileWriter.setResource(new FileSystemResource(exportFilePath));
      csvFileWriter.setLineAggregator(lineAggregator);
  
      return csvFileWriter;
  
  }
  
  @Bean
  public Step exportCSVStep() throws Exception {
      return stepBuilderFactory.get("exportCSVStep")
              .&lt;DmNebefPdhExportRetenuCSV, DmNebefPdhExportRetenuCSV&gt;chunk(100)
              .reader(datamartEffRetenuItemReader(WILL_BE_INJECTED))
              .listener(readListener)
              .writer(exportEffRetenuItemWriter(WILL_BE_INJECTED))
              .listener(writeListener)
              .taskExecutor(taskExecutor())
              .throttleLimit(50)
              .build();
  }
  
  @Bean
  public TaskExecutor taskExecutor() {
      ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor ();
      taskExecutor.setMaxPoolSize(50);
      taskExecutor.afterPropertiesSet();
      return taskExecutor;
  }
  
  @Bean
  public Job exportEffRetenuJob() throws Exception {
      return jobBuilderFactory
              .get("exportEffRetenuJob")
              .incrementer(new RunIdIncrementer())
              .listener(exportEffRetenuJobListener)
              .flow(exportCSVStep()).end().build();
  }
  </code></pre>
  
  <p>I've also tried with new SimpleAsyncTaskExecutor().</p>
  
  <p>Adding setFetchSize() and setPageSize() to my reader, treatment time reduced from 9 minutes to 10 sec.
  But ThreadExecutor doesn't seem to work.</p>
  
  <p>Logs : </p>
  
  <p>Without TaskExecutor : 12,751 seconds</p>
  
  <pre><code>[2018-01-03 11:41:32,087] INFO  ExportEffRetenuJobListener - Start job exportEffRetenuJob - export month 04-2017 
  [2018-01-03 11:41:44,838] INFO  ExportEffRetenuJobListener - End job : exportEffRetenuJob - export month : 04-2017 - statut : COMPLETED
  </code></pre>
  
  <p>With TaskExecutor : 11,328 seconds</p>
  
  <pre><code>[2018-01-03 11:42:55,439] INFO  ExportEffRetenuJobListener - Start job exportEffRetenuJob - export month 04-2017 
  [2018-01-03 11:43:06,767] INFO  ExportEffRetenuJobListener - End job : exportEffRetenuJob - export month : 04-2017 - statut : COMPLETED
  </code></pre>
  
  <p>Test with 240 000 lines to read/write</p>
  
  <p>with TaskExecutor : 123 seconds</p>
  
  <p>Without TaskExecutor : 127 seconds</p>
  
  <p>I think I'm not configuring the task executor well.</p>