Performance: Exception handling in async
MEDIUM IMPACT
This affects how asynchronous errors impact user experience and server responsiveness during async operations.
public @Async CompletableFuture<String> process() {
try {
// async logic
return CompletableFuture.completedFuture("Success");
} catch (Exception e) {
return CompletableFuture.failedFuture(e);
}
}public @Async void process() {
// some async logic
throw new RuntimeException("Error");
}| Pattern | Thread Blocking | Error Visibility | Recovery Speed | Verdict |
|---|---|---|---|---|
| Throwing exceptions in @Async void methods | Blocks threads | Silent failures | Slow recovery | [X] Bad |
| Returning CompletableFuture with exception handling | Non-blocking | Visible errors | Fast recovery | [OK] Good |