Make it easier to execute a method on a particular type of thread #31212
Labels
for: external-project
Needs a fix in external project
in: messaging
Issues in messaging modules (jms, messaging)
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
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 aTaskExecutor
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 theFuture
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
.The text was updated successfully, but these errors were encountered: