Logo Questions Linux Laravel Mysql Ubuntu Git Menu

More than one tasklet in a step?

I have a tasklet setting some information into my JobContext, and another one checking some stuff to know if I can execute the next steps in my batch or not. Both tasklets work well if I use two different steps in my job flow, but I'd like to use these two tasklets in the same step.

I tried to add twice ".tasklet(taskletName)" in my batch configuration like this :

return stepBuilderFactory.get("stepSettings").tasklet(taskletSettings).tasklet(taskletChecking).listener(executionContextListener).listener(stepExecutionListener).build();

It doesn't work: only one of the tasklets is executed (it seems to be the second one). I didn't see anything in spring doc ; is there a way to do this ? Or doesn't Spring allow to have more than one tasklet in the same step ?

like image 669
Carrm Avatar asked Mar 16 '23 18:03


1 Answers

Only one tasklet for step (I think this is by design).
If you need pre-conditions check to flow your job use a JobExecutionDecider.

like image 137
Luca Basso Ricci Avatar answered Mar 27 '23 10:03

Luca Basso Ricci