-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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.