Spring Boot Scheduling

Standards for scheduled tasks and distributed locking with ShedLock

fierzone Updated

File contents

Spring Boot Scheduling Standards

Priority: P0

Implementation Guidelines

Scheduled Tasks

  • ThreadPool: ALWAYS configure a dedicated TaskScheduler (default is 1 thread).
  • Async: Keep @Scheduled methods light; offload to @Async/Queues.

Distributed Locking (ShedLock)

  • Problem: @Scheduled runs on ALL pods in K8s.
  • Solution: Use ShedLock to guarantee single execution.
  • Config: Set lockAtMostFor (deadlock safety) and lockAtLeastFor (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

fierzone/agent-skills-standard/tree/main/skills/spring-boot/scheduling commit 93cc353c1b

Frequently asked questions

npx skillmds@latest add fierzone/spring-boot-scheduling