在Spring Batch中,步骤执行状态不是“已完成”

时间:2019-07-01 13:00:02

标签: java spring-boot spring-batch spring-batch-tasklet

在SpringBatch中,作业未按定义的步骤完成,而是继续从Writer转到Reader, 调试时发现上下文计数增加为1
因为执行状态显示为“可继续”而不是“完成”。

第一步已完成,但第二步有此问题。 请帮助。

@Configuration
@Log4j2
public class PickUpBatchConfig {

    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    private StepExecution stepExecution;


    @Bean
    public Job pickupJob() {
        return this.jobBuilderFactory.get("pickupJob")
            .incrementer(new RunIdIncrementer())
            .listener(new JobResultListener())
            .start(readAndFilterBlockInventoryExtract())
            .next(blockKeyFetch())
            .next(processRequest())
           // .next(sendMessage())
            .build();
    }

    @Bean
    public StepResultListener customStepListener() {
        return new StepResultListener();
    }

    @Bean
    public Step readAndFilterBlockInventoryExtract() {
        System.out.println("*****PickUpBatchConfig.readAndFilterBlockInventoryExtract********");
        return this.stepBuilderFactory.get("step1")
            .<BlockInventoryExtractProcessRequest<ProcessRequest>, BlockInventoryExtractProcessor.BlockInventoryExtractBuilder>chunk(0)
            .reader(new BlockInventoryReader())
            .processor(processor())
            .writer(new BlockInventoryWriter())
            .listener(promotionListener())
            .build();
    }

    @Bean
    public ExecutionContextPromotionListener promotionListener() {
        ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
        listener.setKeys(new String[] {"builder"});
        listener.setStrict(true);
        return listener;
    }


    @Bean
    public ItemProcessor<BlockInventoryExtractProcessRequest<ProcessRequest>, BlockInventoryExtractProcessor.BlockInventoryExtractBuilder> processor() {
        return new BatchBlockInventoryExtractProcessor();
    }



    @Bean
    public Step blockKeyFetch() {
        System.out.println("PickUpBatchConfig.blockKeyFetch");
        return this.stepBuilderFactory.get("step2")
            .<BlockInventoryExtractProcessor.BlockInventoryExtractBuilder,BlockInventoryExtractProcessor.BlockInventoryExtractBuilder>chunk(1)
            .reader(new BlockKeyReader())// Need to implement
            .processor(step2processor())
            .writer(new BlockKeyWriter())
            .listener(promotionListenerStep2())
            .build();
    }

    @Bean
    public ExecutionContextPromotionListener promotionListenerStep2() {
        ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
        listener.setKeys(new String[] {"blockKey"});
        listener.setStrict(true);
        return listener;
    }

    @Bean
    public ItemProcessor<BlockInventoryExtractProcessor.BlockInventoryExtractBuilder,BlockInventoryExtractProcessor.BlockInventoryExtractBuilder> step2processor() {
        return new BlockKeyProcess();
    }

    @Bean
    public Step processRequest() {
        System.out.println("PickUpBatchConfig.processRequest");
        return this.stepBuilderFactory.get("step3")
            .<BlockInventoryExtractProcessor.BlockInventoryExtractBuilder, List<BlockInventoryExtractProcessRequest>>chunk(0)
            .reader(new ProcessRequestReader())//need to implement
            .processor(new ProcessRequestProcessor())
            .writer(new ProcessRequestWriter())
            .listener(promotionListenerStep3())
            .build();
    }

    @Bean
    public ExecutionContextPromotionListener promotionListenerStep3() {
        ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
        listener.setKeys(new String[] {"processRequest"});
        listener.setStrict(true);
        return listener;
    }

0 个答案:

没有答案
相关问题