CallableTaskletAdapter Spring 批处理
CallableTaskletAdapter Spring Batch
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”。这意味着它没有使用新线程。我错过了什么吗?
Does CallableTaskletAdapter use a separate thread than the step itself?
不,它不使用单独的线程。它callsCallable#call
使用执行tasklet的线程。
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”。这意味着它没有使用新线程。我错过了什么吗?
Does CallableTaskletAdapter use a separate thread than the step itself?
不,它不使用单独的线程。它callsCallable#call
使用执行tasklet的线程。