Performance: @Async for async methods
MEDIUM IMPACT
This affects how quickly the server responds to requests by running methods asynchronously, improving user interaction speed.
@Async
public void longTask() throws InterruptedException {
Thread.sleep(5000); // simulate long work
}
@GetMapping("/process")
public String process() {
longTask(); // runs asynchronously
return "done";
}@GetMapping("/process") public String process() throws InterruptedException { longTask(); // runs synchronously return "done"; } public void longTask() throws InterruptedException { Thread.sleep(5000); // simulate long work }
| Pattern | Thread Blocking | Response Delay | Server Load | Verdict |
|---|---|---|---|---|
| Synchronous method call | Blocks main thread | High delay | Lower concurrency | [X] Bad |
| @Async method call | No main thread block | Low delay | Higher concurrency | [OK] Good |