学习笔记spring-batch split


package jp.co.yahoo.vp.batch.configuration;

import jp.co.yahoo.vp.batch.tasklet.ReadAndWriteDbTask;
import jp.co.yahoo.vp.batch.tasklet.ReadAndWriteDbTask2;
import jp.co.yahoo.vp.batch.tasklet.ReadAndWriteDbTask3;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.job.builder.FlowBuilder;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.job.flow.support.SimpleFlow;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;


@Configuration
@EnableBatchProcessing
public class ReadAndWriteDbBatchConfiguration {

    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    // tag::jobstep[]
    @Bean
    public Job readandwritedbJob() {
        Flow flow1 = new FlowBuilder("asyncFlow1").start(step2()).build();
        Flow flow2 = new FlowBuilder("asyncFlow2").start(step3()).build();
        return jobBuilderFactory.get("readandwritedbJob")
                .incrementer(new RunIdIncrementer())
                .flow(step1())
                .split(new SimpleAsyncTaskExecutor()).add(flow1,flow2)
                .end()
                .build();
    }

    @Bean
    public Tasklet tasklet1() {
        return new ReadAndWriteDbTask();
    }

    @Bean
    public Tasklet tasklet2() {
        return new ReadAndWriteDbTask2();
    }


    @Bean
    public Tasklet tasklet3() {
        return new ReadAndWriteDbTask3();
    }

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .tasklet(tasklet1())
                .build();
    }

    @Bean
    public Step step2() {
        return stepBuilderFactory.get("step2")
                .tasklet(tasklet2())
                .build();
    }

    @Bean
    public Step step3() {
        return stepBuilderFactory.get("step3")
                .tasklet(tasklet3())
                .build();
    }
    // end::jobstep[]
}

你可能感兴趣的:(spring,batch)