Reputation: 5
Is there any way to multi thread a JdbcBatchItemWriter. I have a batch which should insert many lines( + 1M lines).
@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;
}
this took me forever.
Upvotes: 0
Views: 899
Reputation: 31600
The JdbcBatchItemWriter
is thread-safe, so you can use it in multiple concurrent transactions. Here is an excerpt from its 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.
So in your case, you can try to use a Multi-threaded Step and see if it improves your job's performance.
Upvotes: 1