Complete the code to annotate a method for asynchronous execution.
@[1]
public void processAsync() {
// async logic
}The @Async annotation marks a method to run asynchronously in Spring Boot.
Complete the code to return a Future object from an async method.
@Async public [1]<String> fetchData() { return new AsyncResult<>("data"); }
The method returns a Future object to represent the result of an async computation.
Fix the error in the async exception handler method signature.
public void handleError([1] ex) {
// handle exception
}Using Throwable allows catching all errors and exceptions in async handlers.
Fill both blanks to correctly define an async exception handler method.
public void [1]([2] ex) { // log or handle exception }
The method name can be handleError and it should accept a Throwable parameter to catch all async exceptions.
Fill all three blanks to create a complete async method with exception handling.
@Async public [1]<String> [2]() { try { // async logic return new AsyncResult<>("success"); } catch ([3] ex) { // handle exception return new AsyncResult<>("failure"); } }
The method returns a Future, is named fetchDataAsync, and catches Exception to handle errors.