I have a Spring Boot Batch job with two primary steps, the first reads a bunch of rows from a spreadsheet. The second writes to a database. Right now, it's set up to write serially to the database.
public CompositeItemWriter<SoftLayerData> compositeSoftlayerDataWriter(
JpaItemWriter<SoftLayerData> softlayerDataWriter) {
CompositeItemWriter<SoftLayerData> compositeWriter = new CompositeItemWriter<>();
compositeWriter.setDelegates(asList(softlayerDataWriter));
return compositeWriter;
}
The problem is the volume is large. Since there's no reason to maintain any order, I'd like to have multiple writers. I tried this:
final int writerCount = 10;
List<ItemWriter<? super SoftLayerData>> writers = new ArrayList<>(writerCount);
for(int counter=0;counter<writerCount;counter++) {
writers.add(new JpaItemWriter<SoftLayerData>());
}
CompositeItemWriter<SoftLayerData> result = new CompositeItemWriter<>();
result.setDelegates(writers);
return result;
But I'm getting an IllegalArgumentException: No EntityManagerFactory specified
.
I like the approach, but I suspect there's some really complex Spring Boot way that I have to follow. What's the best approach to doing multiple writers?