JdbcBatchItemWriter 多线程

JdbcBatchItemWriter multi thread

有没有办法对 JdbcBatchItemWriter 进行多线程处理。 我有一批应该插入很多行(+ 1M 行)。

@Bean
public JdbcBatchItemWriter<MyDTO> InitWriter() {
    JdbcBatchItemWriter<MyDTO> writer = new JdbcBatchItemWriter<MyDTO>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<MyDTO>());
    writer.setSql("INSERT INTO ....");
    writer.setDataSource(cloudDataSource);

    return writer;
}

这让我终生难忘。

JdbcBatchItemWriter 是线程安全的,因此您可以在多个并发事务中使用它。这是其 Javadoc:

的摘录

The writer is thread-safe after its properties are set (normal singleton behavior), so it can be used to write in multiple concurrent transactions.

所以在你的情况下,你可以尝试使用 Multi-threaded Step 看看它是否能提高你的工作绩效。