A->B->C の順序で実行する必要がある 3 つのステップ A、B、C があり、B はオプションです。いくつかの条件に基づいてのみステップ B を実行する必要があります。JobExecutionDecider を使用して、次のように決定しています。
@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");
}
};
}
ジョブ構成には、次のスニペットがあります。
@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();
上記のコードは期待どおりに機能しています。しかし、これが正しい方法であるかどうかはわかりません。基本的に、ステップ C の実行を繰り返さない方法を期待しています。
SimpleAsyncTaskExecutor に出くわしましたが、並列処理を行う必要があるシナリオで使用されることを理解しました。私の場合、条件が満たされた場合にステップを実行するだけです。
私の質問は 1. SimpleAsyncTaskExecutor を使用して目的を達成できますか? 注釈を使用して SimpleAsyncTaskExecutor を使用する例はありますか? 2.上記の重複を避けることができる、私が行ったことを行うための他のより良い方法はありますか?
どんな助けでも本当に感謝しています!
前もって感謝します、 ディネッシュ・クマール P