Reader只运行一次

时间:2017-10-11 13:11:21

标签: java spring spring-batch batch-processing

我有一个批处理工作,其中我有一个步骤,可以在国家/地区列表中获取和存储有关每个国家/地区的信息。我使用过分区工作,但有人要求我不要使用它。我们可以使用任何方法来完成同样的行为吗?

我的工作配置如下

  private Job batchJob() {
        return jobBuilderFactory.get(jobName)
                .incrementer(new RunIdIncrementer())
                .start(jobFlow())
                .end()
                .build();
      }

private JobExecutionDecider jobExecutionDecider(CountryConfig countryConfig) {

     return new JobExecutionDecider() {
       @Override
       public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
         System.out.println("JED: status: "+ (countryConfig.hasNextCountry() ? new FlowExecutionStatus("CONTINUE") : new FlowExecutionStatus("FINISHED")));
         return countryConfig.hasNextCountry() ? new FlowExecutionStatus("CONTINUE") : new FlowExecutionStatus("FINISHED");
       }
     };
  }

      private Flow jobFlow() {
        SimpleFlow simpleFlow = new SimpleFlow(jobName + "_flow");
        List<StateTransition> transitions = new LinkedList<>();
        transitions.add(StateTransition.createStateTransition(new StepState(step()), "decision"));
        transitions.add(StateTransition.createStateTransition(new DecisionState(jobExecutionDecider(countryConfig()), "decision"), "CONTINUE", stepName ));
        transitions.add(StateTransition.createEndStateTransition(new DecisionState(jobExecutionDecider(countryConfig()), "decision"), "*"));
        simpleFlow.setStateTransitions(transitions);
        return simpleFlow;
      }
      protected Step step() {
        return stepBuilderFactory.get(stepName)
                .allowStartIfComplete(true)
                .<SiloNavTreeReaderResponse, SiloNavTreeProcessorResponse>chunk(1)
                .reader(reader())
                .processor(processor())
                .writer(writer())
                .build();
      }

0 个答案:

没有答案