agentleFS
rrezartprebrezarrezartprebreza/spring-boot-skills/skills/spring-boot-3/scheduled-tasks/SKILL.md

scheduled-tasks

Skill369 starsChanged 4 months agoMITView on GitHub

Use when creating or reviewing @Scheduled jobs, cron/time-zone configuration, overlapping runs or multi-instance scheduling. Not for Spring Batch chunk/restart mechanics or arbitrary async dispatch.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Framework 6 scheduling APIs and the project's Boot BOM.

    line 11
  2. Distinctive:

    Every application instance can register the trigger.

    line 34
  3. Distinctive:

    Keep the scheduling adapter small.

    line 44
  4. Distinctive:

    Use the project's scheduler shutdown policy and deployment grace period.

    line 53
  5. Distinctive:

    Test cron parsing and disabled configuration without waiting for wall-clock runs.

    line 57

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Scheduled Tasks

Spring Boot 3 baseline

Use Framework 6 scheduling APIs and the project's Boot BOM; the template uses Java 17. Reactive scheduled methods and virtual-thread scheduling require the appropriate Framework 6.1+/Boot 3.2+ baseline. Do not copy those features into older Boot 3 applications.

Trigger contract

Establish schedule, time zone, maximum run duration, missed-run behavior and replica count before choosing an implementation. Enable scheduling once. Spring cron has six fields, including seconds. Specify a zone rather than relying on a deployment host default, and test daylight-saving transitions when the business contract uses local time.

Fixed delay measures from completion; fixed rate follows a start-time cadence. Neither is a cluster-wide lock. Adding @Async detaches completion from the scheduled invocation and can allow overlapping work. Multiple scheduled declarations or bean instances can also duplicate execution. Do not change an existing cadence just to hide a slow job.

StaleOrderSchedule is a thin, disabled-by-default cron adapter. Supply a Clock and a SweepAction bean; enable @EnableScheduling in configuration. Good configuration requires an explicit cron to enable it; the bad example starts untracked duplicate work.

Replicas and durable work

Every application instance can register the trigger. Decide whether all replicas may work, one leader triggers, or workers claim disjoint persisted items. Reuse existing coordination (for example a clustered scheduler or a tested lease library); do not invent a JVM boolean lock or call Redis SETNX without ownership, expiry and stale-owner handling.

A lease can expire while the original worker is still running. Use idempotent effects and, where stale owners can corrupt state, fencing checked by the protected resource. A lock alone does not provide exactly-once effects. Persist progress and retry intent for mandatory work; Spring's in-process schedule does not replay missed fires after downtime.

Keep the scheduling adapter small. Let a separate service claim a bounded batch and enforce tenant boundaries and transaction rules. Avoid one transaction over an unbounded scan or a remote call. Handle uncertain external outcomes with provider idempotency or reconciliation. The template's SweepAction is an application integration point, not an implemented lock or queue.

Operations and verification

Set runtime and I/O limits. Observe last successful completion, duration, failures and backlog age using bounded metric labels. Logging an exception is not a retry or an alerting policy. Use the project's scheduler shutdown policy and deployment grace period; interruption does not automatically roll back remote effects. Virtual threads still need downstream limits; fixed-delay tasks on SimpleAsyncTaskScheduler share its scheduler thread.

Test cron parsing and disabled configuration without waiting for wall-clock runs. Inject a Clock into time-dependent work. Add integration tests for competing replicas, lease expiry, partial failure and restart when using coordination. The included fixture checks the adapter and trigger registration only; it does not implement distributed scheduling.

Gotchas

  • Agent uses a five-field Unix cron - include Spring's seconds field and verify next fire times.
  • Agent assumes @Scheduled runs once across replicas - define explicit coordination or safe duplicate work.
  • Agent adds @Async to fix a slow timer - bound and test overlapping execution instead.
  • Agent relies on a lease for exactly-once effects - account for expiry, stale owners and duplicates.
  • Agent silently enables a destructive maintenance job - require explicit configuration and authorization.
  • Agent tests timing with long sleeps - use a fixed Clock and direct trigger calculations.

Official sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.