Spring MVC and @Async

I have a long service method (maintaining business logic), and I would like the client to immediately send a request to the controller. I would like the client to periodically conduct a survey to check if the service method is complete. After reading these two links: link1 link2 I am convinced that @Asyncthis is the right approach for my situation. My question is which service method or Controller method should have annotation @Async. And exactly how the method Controllerrefers to the Future object so that it can call its methods get()or isDone().

+3
source share
1 answer

Put @Async on a service method that calls the "real" service method. So you have two ways to call it, asynchronous and non-asynchronous.

Ask the controller method to keep the future returned by the service in the session, and then return. Then, when the client polls the controller (using a different URL / method), the controller can infer the Future from the session and call isDone () on it.

+11
source

All Articles