I am using a Spring MVC controller and want to start the execution of a task in a new thread. However the task should not start immediately but only after the response has been sent to the client.
The sequence - in strict temporal order:
- request
- return new
ResponseEntity ...
/ client receives HTTP status 200 OK. - processing of the task begins.
How do I achieve this?
I wanted to use Spring's async abstraction by calling a method annotated with @Async, but it does not guarantee that the new thread waits for the response to be sent first.