Java 在Spring批处理中动态设置gridSize(线程数)
我在Java 在Spring批处理中动态设置gridSize(线程数),java,multithreading,spring-boot,spring-batch,Java,Multithreading,Spring Boot,Spring Batch,我在springboot项目中有一个spring批处理,它处理输入文件中的记录 输入文件中的记录数可以在100万到100万之间变化 如前所述,我希望通过对批进行分区来利用多线程 但是我希望生成的线程数量应该根据输入文件中记录的数量来决定 比如说,如果记录是10000&&,您可以使用惰性作用域,使用@StepScope注释来设置网格大小 选项1:如果要从stepExecutionContext设置网格大小 @Bean @StepScope public PartitionHandler mas
springboot
项目中有一个spring批处理
,它处理输入文件中的记录
输入文件中的记录数可以在100万到100万之间变化
如前所述,我希望通过对批进行分区来利用多线程
但是我希望生成的线程数量应该根据输入文件中记录的数量来决定
比如说,如果记录是10000&&,您可以使用惰性作用域,使用
@StepScope
注释来设置网格大小
选项1:如果要从stepExecutionContext设置网格大小
@Bean
@StepScope
public PartitionHandler masterSlaveHandler(@Value("#{stepExecutionContext[gridSize]}") int gridSize) {
TaskExecutorPartitionHandler handler = new TaskExecutorPartitionHandler();
handler.setGridSize(gridSize);
handler.setTaskExecutor(taskExecutor());
handler.setStep(slave());
try {
handler.afterPropertiesSet();
} catch (Exception e) {
e.printStackTrace();
}
return handler;
}
选项1:如果要根据作业参数设置网格大小
@Bean
@StepScope
public PartitionHandler masterSlaveHandler(@Value("#{jobParameters[gridSize]}") int gridSize) {
TaskExecutorPartitionHandler handler = new TaskExecutorPartitionHandler();
handler.setGridSize(gridSize);
handler.setTaskExecutor(taskExecutor());
handler.setStep(slave());
try {
handler.afterPropertiesSet();
} catch (Exception e) {
e.printStackTrace();
}
return handler;
}
@Bean
@StepScope
public PartitionHandler masterSlaveHandler(@Value("#{jobParameters[gridSize]}") int gridSize) {
TaskExecutorPartitionHandler handler = new TaskExecutorPartitionHandler();
handler.setGridSize(gridSize);
handler.setTaskExecutor(taskExecutor());
handler.setStep(slave());
try {
handler.afterPropertiesSet();
} catch (Exception e) {
e.printStackTrace();
}
return handler;
}