Performance: Scheduled tasks with @Scheduled
MEDIUM IMPACT
This affects the backend task execution timing and resource usage, indirectly impacting frontend responsiveness and server load.
@Scheduled(fixedDelay = 1000)
public void lightTask() {
// quick non-blocking logic
CompletableFuture.runAsync(() -> {
// heavy processing off main scheduler thread
});
}@Scheduled(fixedDelay = 1000) public void heavyTask() throws InterruptedException { // heavy processing blocking thread Thread.sleep(5000); // task logic }
| Pattern | Thread Usage | Task Overlap | Server Load | Verdict |
|---|---|---|---|---|
| Blocking long task in @Scheduled | Single scheduler thread blocked | Possible overlap and delays | High CPU and thread contention | [X] Bad |
| Async processing inside @Scheduled | Scheduler thread free quickly | No overlap, tasks run timely | Lower CPU spikes, balanced load | [OK] Good |