I have 3 steps A, B, C which should execute in the sequence A->B->C where B is optional. I've to execute step B only based on some condition. I'm using JobExecutionDecider to decide as follows:
@Bean(name = "decider")
JobExecutionDecider isStepRequired {
return new JobExecutionDecider() {
@Override
public FlowExecutionStatus decide(final JobExecution jobExecution, final StepExecution stepExecution) {
if (condition not satisfied) {
// return status to skip step B and go to step C
return FlowExecutionStatus.COMPLETED;
}
// return status to proceed with step B
return new FlowExecutionStatus("CONTINUE");
}
};
}
and in the job configuration, i have the following snippet,
@Bean
Job constructJob(final JobBuilderFactory jobs, final Step a, final Step b, final JobExecutionDecider decider, final Step c) {
final JobBuilder jobBuilder = jobs.get("Job");
final JobFlowBuilder builder = jobBuilder.flow(a);
builder.from(a).next(decider);
builder.from(decider).on("CONTINUE").to(b).next(c);
builder.from(decider).on("*").to(c);
return builder.build().build();
and the above mentioned code is working as i expected. But I'm not sure whether this is the right way of doing it. Basically I'm expecting a way not to repeat the step C execution.
I did come across SimpleAsyncTaskExecutor but i understood that it is used in a scenario where we need to do parallel processing and in my case i just have to execute a step if the condition satisfies.
My questions are 1. Can I achieve what I want by using SimpleAsyncTaskExecutor? Is there any example of using SimpleAsyncTaskExecutor using annotation? 2. Is there any other better way of doing what I've done where I can avoid the above mentioned duplication?
Any help is really appreciated!
Thanks in advance, Dhinesh Kumar P