1

I want to configure a Spring Batch job with 4 steps. Step-2 and Step-3 are independent to each other. So I want to execute then in parallel. Any of these 2 steps or both can be skipped depending on Execution Parameter. Check the flow as mentioned below : Batch flow details

Java Configuration as mentioned below:

@Bean
public Job sampleBatchJob()
    throws Exception {

final Flow step1Flow = new FlowBuilder<SimpleFlow>("step1Flow")
        .from(step1Tasklet()).end();

final Flow step2Flow = new FlowBuilder<SimpleFlow>("step2Flow")
        .from(new step2FlowDecider()).on("EXECUTE").to(step2MasterStep())
        .from(new step2FlowDecider()).on("SKIP").end(ExitStatus.COMPLETED.getExitCode())
        .build();
final Flow step3Flow = new FlowBuilder<SimpleFlow>("step3Flow")
        .from(new step3FlowDecider()).on("EXECUTE").to(step3MasterStep())
        .from(new step3FlowDecider()).on("SKIP").end(ExitStatus.COMPLETED.getExitCode())
        .build();

final Flow splitFlow = new FlowBuilder<Flow>("splitFlow")
        .split(new SimpleAsyncTaskExecutor())
        .add(step2Flow, step3Flow)
        .build();

return jobBuilderFactory().get("sampleBatchJob")
        .start(step1Flow)
        .next(splitFlow)
        .next(step4MasterStep())
        .end()
        .build();
}

Sample code for Step2FlowDecider:

public class Step2FlowDecider
    implements JobExecutionDecider {
@Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {

    if (StringUtils.equals("Y", batchParameter.executeStep2())) {
        return new FlowExecutionStatus("EXECUTE");
    }
    return new FlowExecutionStatus("SKIP");
}

}

With this configuration, when I try to execute the batch, it is getting failed, without any details error log.

Suman Das
  • 11
  • 3
  • `it is getting failed` do yo mean the job status is FAILED? Please enable debug logs and share any relevant information. – Mahmoud Ben Hassine Jun 10 '20 at 09:03
  • Yes, job status is failed. Seems the problem is in decider. Without it, it is working, but when trying to execute the flow based on decider, the job is getting failed. Even not showing any error details in log. – Suman Das Jun 10 '20 at 12:43
  • Have you set debug log level? Please provide a minimal example that reproduces the issue to be able to help you: https://stackoverflow.com/help/minimal-reproducible-example. – Mahmoud Ben Hassine Jun 15 '20 at 08:31

0 Answers0