I have a file of 50K records. It takes close to 40 mins to insert it into a DB. So I thought of applying a partition to the step in such a way that the 50k records are partitioned between 10 threads (via gridSize
) with each thread processing 1000 records in parallel.
All the forums show examples of using JDBCPagingItemReader
and partitioned count set via execution context.
Since I am using MultiResourceItemReader
, how can I set the partition count(startingIndex
and endingIndex
- refer code snippet below) for MultiResourceItemReader
?
Please advise.
Code snippet of partitioner below:
public Map partition(int gridSize) {
LOGGER.debug("START: Partition");
Map partitionMap = new HashMap();
int startingIndex = 0;
int endingIndex = 1000;
for(int i=0; i< gridSize; i++){
ExecutionContext ctxMap = new ExecutionContext();
ctxMap.putInt("startingIndex",startingIndex);
ctxMap.putInt("endingIndex", endingIndex);
startingIndex = endingIndex+1;
endingIndex += 1000;
partitionMap.put("Thread:-"+i, ctxMap);
}
LOGGER.debug("END: Created Partitions of size: "+ partitionMap.size());
return partitionMap;
}