CallableTaskletAdapterは、ステップ自体とは別のスレッドを使用しますか?
@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();
}
このコードを実行すると、呼び出し可能なタスクレットにスレッド名が「main」として出力されます。つまり、新しいスレッドを使用していません。何か不足していますか?
CallableTaskletAdapterは、ステップ自体とは別のスレッドを使用しますか?
いいえ、別のスレッドは使用しません。タスクレットを実行するスレッドを使用して呼び出します Callable#call
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加