Reputation: 7647
Spring Controller REST methods are by default Asynchronized.
Then what is the purpose of @Async annotation?
@RequestMapping(value = "/status/{id}", method = RequestMethod.GET)
@Async
public Future<Status> getStatus(@PathVariable("id") String id) {
return new AsyncResult<Status>(status);
}
Also what is the role of Future interface and AsyncResult class?
Upvotes: 1
Views: 4633
Reputation: 2477
@Async : Can be used for fire-and-forget scenarios, such as sending an email, kicking off a database job. Caller immediately get the response, while a background job completes processing.
what is the role of Future interface and AsyncResult class?
Future represents the result of an asynchronous computation.
AsyncResult is an implementation for Future, wraps the return type of asynchronous execution.
As per this blog, Callable is the appropriate return type for controller methods.
ref Async vs callable controllers
Upvotes: 3