Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring批处理中动态设置gridSize(线程数)_Java_Multithreading_Spring Boot_Spring Batch - Fatal编程技术网

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;
  }