Skip to content

Make it easier to execute a method on a particular type of threadΒ #31212

@wilkinsona

Description

@wilkinsona

Affects: 6.1

With the introduction of virtual thread support, I anticipate that there will be an increased need for executing a method on a particular type of thread. Specifically, when a Servlet web server is using virtual threads for request handling, I anticipate a need to switch execution to a platform thread to avoid pinning of virtual threads caused by unavoidable synchronization in third-party code. This Tomcat mailing list discussion is one example of this problem.

This can be achieved today using an @Async annotated method that references a TaskExecutor that is using platform threads but it comes with a reasonably large amount of boiler plate as you have to move code into a separate method and work with the Future API.

To simplify things, I would like Framework to deal with the Future on my behalf so that I can write a "normal" method and have it automatically run on a thread from a particular task executor. There's prior art for this sort of functionality in Micronaut with its @ExecuteOn annotation. In a Spring app, I envisage that a similar annotation could be used on any method that's an entry point into the application such as a method on a @Controller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectNeeds a fix in external projectin: messagingIssues in messaging modules (jms, messaging)in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions