spring-projects / spring-projects/spring-security

Better docs on "inter-op" with @Async

Open
#18,207 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring Security concurrency integration documentation linked in the issue and compare its guidance with the provided @Async, virtual-thread, and DelegatingSecurityContextAsyncTaskExecutor examples. Done means the official documentation clearly explains the recommended virtual-thread configuration and how Spring Security context propagation works with it.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.