Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring boot 使用Spring批处理同时(并发)处理通过ItemReader读取的多个对象_Spring Boot_Spring Batch_Batch Processing_Spring Batch Admin_Spring Boot Admin - Fatal编程技术网

Spring boot 使用Spring批处理同时(并发)处理通过ItemReader读取的多个对象

Spring boot 使用Spring批处理同时(并发)处理通过ItemReader读取的多个对象,spring-boot,spring-batch,batch-processing,spring-batch-admin,spring-boot-admin,Spring Boot,Spring Batch,Batch Processing,Spring Batch Admin,Spring Boot Admin,我试图从数据库中读取数据,并在每个对象上同时运行进程 我的配置如下: 作者如下: @覆盖 public void write(List不必深入了解定制阅读器/处理器/写入器的细节,我认为您需要的是 如上述链接文档中所述,为了使步骤多线程化(意味着在单独的线程中读取/处理/写入每个块),您首先需要注册一个SimpleAsyncTaskExecutor: @Bean public TaskExecutor taskExecutor(){ return new SimpleAsyncTaskE

我试图从数据库中读取数据,并在每个对象上同时运行进程

我的配置如下:

作者如下:

@覆盖

public void write(List不必深入了解定制阅读器/处理器/写入器的细节,我认为您需要的是

如上述链接文档中所述,为了使步骤多线程化(意味着在单独的线程中读取/处理/写入每个块),您首先需要注册一个
SimpleAsyncTaskExecutor

@Bean
public TaskExecutor taskExecutor(){
    return new SimpleAsyncTaskExecutor("myAsyncTaskExecutor");
}
然后在步骤的生成器中注册此任务执行器:

@Bean
public Step step1() {
    return stepBuilderFactory.get("step1")
            .<VideosDTO, VideosDTO>chunk(3)
            .reader(databaseVideoItemReader(null))
            .processor(new Processor())
            .writer(new Writer(videoDao))
            //making the Step multi-threaded
            .taskExecutor(taskExecutor())
            .build();
}
@Bean
公共步骤第1步(){
返回stepBuilderFactory.get(“step1”)
.chunk(3)
.reader(数据库VideoItemReader(空))
.processor(新处理器())
.编剧(新编剧(videoDao))
//使步骤多线程化
.taskExecutor(taskExecutor())
.build();
}

使用@dimitrisli建议的多线程步骤是一种方法。除此之外,另一种方法是使用(与
AsyncItemWriter
结合使用)

在这里可以找到一个类似的用例(从处理器异步调用rest端点):我在这里给出了更多细节

希望这有帮助

    @Override
public void write(List<? extends VideosDTO>videosList) throws Exception {

    for(VideosDTO vid:videosList){
        log.info("writting...."+vid.getVideoUrl());
    }

}
@Bean
public TaskExecutor taskExecutor(){
    return new SimpleAsyncTaskExecutor("myAsyncTaskExecutor");
}
@Bean
public Step step1() {
    return stepBuilderFactory.get("step1")
            .<VideosDTO, VideosDTO>chunk(3)
            .reader(databaseVideoItemReader(null))
            .processor(new Processor())
            .writer(new Writer(videoDao))
            //making the Step multi-threaded
            .taskExecutor(taskExecutor())
            .build();
}