Spring Boot Scheduling Standards
Priority: P0
Implementation Guidelines
Scheduled Tasks
- ThreadPool: ALWAYS configure a dedicated
TaskScheduler(default is 1 thread). - Async: Keep
@Scheduledmethods light; offload to@Async/Queues.
Distributed Locking (ShedLock)
- Problem:
@Scheduledruns on ALL pods in K8s. - Solution: Use ShedLock to guarantee single execution.
- Config: Set
lockAtMostFor(deadlock safety) andlockAtLeastFor(debounce).
Anti-Patterns
- Default Pool:
**No Default Pool**: Configure ThreadPool. - No Locking:
**No duplicates**: Use Distributed Lock. - Stateful Tasks:
**No State**: Assume pod restarts.
References
- Implementation Examples