title: Spring batch (spring boot - java config) multithreaded jdbc writer
body: <p>I need to write a huge amount of data into mysql.</p>
  
  <p>I want to do it in several threads or performance. I would like to use spring batch partitioning but never done this before.</p>
  
  <p>My spring batch java config (part):</p>
  
  <pre><code>@Bean
  ItemWriter&lt;Event&gt; writer() throws SQLException {
      return new CustomJdbcBatchDataWriter();
  }
  
  @Bean
  public TaskExecutor taskExecutor(){
      SimpleAsyncTaskExecutor asyncTaskExecutor=new SimpleAsyncTaskExecutor("spring_batch");
      asyncTaskExecutor.setConcurrencyLimit(threadsAmount);
      return asyncTaskExecutor;
  }
  
  @Bean
  public Job importUserJob(JobCompletionNotificationListener listener) throws Exception {
      return jobBuilderFactory.get("importUserJob")
              .incrementer(new RunIdIncrementer())
              .listener(listener)
              .flow(step1())
              .end()
              .build();
  }
  
  @Bean
  public Step step1() throws Exception {
      return stepBuilderFactory.get("step1")
              .&lt;Event, Event&gt;chunk(chunkSize)
              .reader(reader())
              .processor(processor())
              .writer(writer())
              .taskExecutor(taskExecutor())
              .build();
  }
  </code></pre>
  
  <p>And my custom jdbc writer (had to write it to disable autocommit - for performance):</p>
  
  <p>public class CustomJdbcBatchDataWriter implements ItemWriter {</p>
  
  <pre><code>@Override
  public void write(List&lt;? extends Event&gt; items) throws Exception {
  try (
      Connection connection = DriverManager.getConnection(
              "jdbc:mysql://localhost:3306/batch?useSSL=false&amp;useServerPrepStmts=false&amp;rewriteBatchedStatements=true",
              "user", "password") ) {
      connection.setAutoCommit(false);
  
  
      String sql = "INSERT INTO events VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
      PreparedStatement ps = connection.prepareStatement(sql);
  
      for (Event p : items) {
          try {
              ps.setString(1, p.getId());
         //Setting rest of data into prepared statement
         ...
              ps.addBatch();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  
      ps.executeBatch();
      connection.commit();
  }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>How can I configure this so it will insert different data in different threads to gain performance?
  Any help is really appreciated.</p>