![](/img/trans.png)
[英]Spring-Batch: writing a Partitioner for a unknown number of partitions
[英]Step initialization time too long using Partitioner in Spring-Batch?
我正在使用Partitioner
来并行化*.csv
文件的导入。 该文件夹中大约有3万个文件。
问题:在初始化所有文件之前,作业初始化大约需要1-2h小时。 瓶颈在SimpleStepExecutionSplitter.split()
。
问题:步骤初始化需要那么多时间正常吗? 还是我可以以某种方式改进它?
@Bean
public Step partitionStep(Partitioner partitioner) {
return stepBuilderFactory.get("partitionStep")
.partitioner(step())
.partitioner("partitioner", partitioner)
.taskExecutor(taskExecutor())
.build();
}
@Bean
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(4); //run import always with 4 parallel files
taskExecutor.setMaxPoolSize(4);
taskExecutor.afterPropertiesSet();
return taskExecutor;
}
@Bean
public Partitioner partitioner() throws IOException {
MultiResourcePartitioner p = new MultiResourcePartitioner();
p.setResources(new PathMatchingResourcePatternResolver().getResources("mypath/*.csv"));
return p;
}
我使用自定义拆分器,因为在默认拆分器中( https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core /partition/support/SimpleStepExecutionSplitter.java ),你叫jobRepository.getLastStepExecution
每个StepExecution
。 我不会在spring-batch中使用可重新启动性,因此我可以编写自己的分离器。 现在,步骤初始化需要几秒钟来处理数千个文件(之前是几分钟)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.