Based on the current thinking of “Boot will provide a single configuration property that a user can set to opt in to the use of virtual threads everywhere”, if the user sets that property, then Boot should set the VirtualThreadTaskExecutor on the JobLauncher of Batch.

Spring Batch issue: https://github.com/spring-projects/spring-batch/issues/4399

Comment From: wilkinsona

@fmbenhassine given that the default is a SyncTaskExecutor, it feels like quite a big jump to use a VirtualThreadTaskExecutor when virtual threads are enabled. If it makes sense to use multiple threads when virtual threads when they're enabled, does it not also make sense to use multiple threads the rest of the time?

Comment From: fmbenhassine

@wilkinsona

given that the default is a SyncTaskExecutor, it feels like quite a big jump to use a VirtualThreadTaskExecutor when virtual threads are enabled.

This is based on the thinking shared above, which states that if the property is set, virtual threads should be used everywhere, ie including the job launcher. Do you think we need to make an exception here and keep using the SyncTaskExecutor for that? One thing to pay attention to if we use a VirtualThreadTaskExecutor in the job launcher is that the boot app should wait for the job execution to complete (as the executor is asynchronous), otherwise it might exit before the job is finished.

If it makes sense to use multiple threads when virtual threads when they're enabled, does it not also make sense to use multiple threads the rest of the time?

I am not sure I get this. To my knowledge, the only part of Batch that uses a TaskExecutor and that Boot auto-configures is the JobLauncher. Other parts where TaskExecutors are used (concurrent steps, parallel steps, etc) are typically configured manually by the user (by autowiring the executor autoconfigured by Boot and setting it where appropriate), and are not affected by this story. Is that what you mean by the rest of the time?

Comment From: wilkinsona

Is that what you mean by the rest of the time?

By "the rest of the time", I meant when virtual threads are not enabled. So configure ThreadPoolTaskExecutor normally and a VirtualThreadTaskExecutor when virtual threads are enabled.

This is based on the thinking shared above, which states that if the property is set, virtual threads should be used everywhere, ie including the job launcher.

It's really everywhere that was already multi-threaded. In other words, enabling virtual threads should change the type of threads that are used for multi-threading, not necessarily switch from synchronous to asynchronous.

In all in, it sounds to me like we should close this issue without making any changes. WDYT?

Comment From: fmbenhassine

Thanks for the clarification, Andy! Now I understand better the intent of that property. In that case, I see no need to switch from synchronous to asynchronous in the job launcher, and since this is the only Batch thing related to threads that boot auto-configures, this issue can be closed without any changes.