Does CallableTaskletAdapter use a separate thread than the step itself?
@Bean
public Callable<RepeatStatus> callableObject() {
return () -> {
System.out.println(Thread.currentThread().getName());
System.out.println("This was executed in another thread");
return RepeatStatus.FINISHED;
};
}
@Bean
public CallableTaskletAdapter tasklet() {
CallableTaskletAdapter callableTaskletAdapter =new CallableTaskletAdapter();
callableTaskletAdapter.setCallable(callableObject());
return callableTaskletAdapter;
}
@Bean
public Step callableStep() {
System.out.println(Thread.currentThread().getName());
return this.stepBuilderFactory.get("callableStep")
.tasklet(tasklet())
.build();
}
Running this code prints the thread name as "main" in callable tasklet. Which means it is not using the new thread. Am I missing something?
Does CallableTaskletAdapter use a separate thread than the step itself?
No, it does not use a separate thread. It calls Callable#call
using the thread executing the tasklet.