Skip to content

Better docs on "inter-op" with @Async #18207

@gregjotau

Description

@gregjotau

As far as I understand when using Virtual threads you should not use Thread pools like this:

@Configuration
class ServiceExecutorConfig : AsyncConfigurer {
    override fun getAsyncExecutor(): Executor {
        val taskExecutor = ThreadPoolTaskExecutor().apply {
            corePoolSize = 15
            maxPoolSize = 50
            setQueueCapacity(100)
            initialize()
        }
        return DelegatingSecurityContextAsyncTaskExecutor(taskExecutor)
    }
}

But instead something like:

@Configuration
@EnableAsync
class AsyncConfig(
    private val builder: SimpleAsyncTaskExecutorBuilder
) {

    @Bean(name = ["secExecutor"])
    fun secExecutor(): AsyncTaskExecutor {
        // With spring.threads.virtual.enabled=true this builder creates
        // a SimpleAsyncTaskExecutor that uses a *new virtual thread per task*.
        val delegate = builder
            .threadNamePrefix("async-")
            .build()

        return DelegatingSecurityContextAsyncTaskExecutor(delegate)
    }
}

I'm trying to find good official docs on how to handle this, the first results are blogs recommending the ThreadPoolTaskExecutor approach.

I also find this, which does not cover a simple way of making Spring security work with Async out of the box:

https://docs.spring.io/spring-security/reference/features/integrations/concurrency.html

I'm not sure if this is something that it would make sense if the framework just solved with reasonable defaults?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions