I would like to know the general use case of using @Async and Servlet 3 asynchronous request implementation in Spring using Callable.
As I understand, @Async is for making any method (specifically, any service method) execute asynchronously.
@Async
void doSomething(String s) {
// this will be executed asynchronously
}
and any controller which returns Callable
@RequestMapping("/view")
public Callable<String> callableWithView(final Model model) {
return new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep(2000);
model.addAttribute("foo", "bar");
model.addAttribute("fruit", "apple");
return "views/html";
}
};
}
I am confused on whento use what. What will be the effect of using Asynchronous servlet/controller and with spring @Async together?