Description
I have seen the conversation in spring-projects/spring-framework#34393, but I wanted to re-open the conversation because I disagree with the reasoning for why the issue was closed as won't fix and would like to make a new case to help people avoid the issue I see my teams running into constantly.
To recap, when a developer sets spring.threads.virtual.enabled
to true, they have what I think is a reasonable expectation that the Spring framework will do it's best to make choices to configure anything that it can configure to use virtual threading for them. It does this in a lot of cases and, one of those cases, is to configure the default SimpleAsyncTaskExecutor
to use virtual threads.
In the case of JDKClientHttpRequestFactory
it will detect that no executor has been set on the HttpClient and create a brand new, dedicated SimpleAsyncTaskExecutor
, but it doesn't bother consulting the spring.threads.virtual.enabled
setting to see if it should be configured to use virtual threads.
IMHO, this level of indirection that JDKClientHttpRequestFactory
provides is Spring's chance to "help" meet the expectations of developers and, today, it doesn't.
NOTE: if the developer "brings their own" HttpClient
and it happens to have an executor already set, the logic in JDKClientHttpRequestFactory
already won't override it, so making changes here should be non-breaking. It's really just about updating the implementation to configure the dedicated SimpleAsyncTaskExecutor
with virtual threads when spring.threads.virtual.enabled
is true
.