Class Scheduler
Runs the @Scheduled methods of a server.
The build registers each job from the entry point it generates -- the cron masks already computed, the executor and thread kind already chosen -- and starts this once the server is accepting. One platform thread keeps the timetable; the jobs themselves run on their executors, so a slow job delays nothing but its own next run.
A run never overlaps the previous run of the same job. A fire that finds the previous run still going is skipped, and the job is next due at its following time, which is what keeps a job that has fallen behind from stacking up copies of itself.
With a lock, a run first claims a row in cn1_scheduler_lock
and is skipped when another instance holds it, so a job runs on one replica
at a time. The claim expires after lockAtMostFor milliseconds, so a
replica that dies mid-run does not keep it.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne registered job and what has happened to it. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidTakes the measuring and tracing of the server that runs this scheduler.voidcron(String name, CronSchedule schedule, String executor, int threadKind, String lock, long lockAtMostFor, Runnable body) Registers a cron job.describe()Every job and what has happened to it, for the management endpoint and MCP.voidfixedDelay(String name, long initialDelay, long period, String executor, int threadKind, String lock, long lockAtMostFor, Runnable body) Registers a job that startsperiodmilliseconds after the last run ended.voidfixedRate(String name, long initialDelay, long period, String executor, int threadKind, String lock, long lockAtMostFor, Runnable body) Registers a job that starts everyperiodmilliseconds.getJobs()The registered jobs.voidsetMeasured(boolean measured) Set by the server once it knows whether it records metrics.voidstart()Starts the timetable.voidstop(long waitMillis) Stops starting runs and waits up towaitMillisfor the ones in progress.booleanRuns a job now, on its executor, whatever its schedule says.
-
Field Details
-
CRON
public static final int CRON- See Also:
-
FIXED_RATE
public static final int FIXED_RATE- See Also:
-
FIXED_DELAY
public static final int FIXED_DELAY- See Also:
-
-
Constructor Details
-
Scheduler
Parameters
locks: @param locks the pool locked jobs claim their row in, or null when this server has no database -- the build refuses a lock without one
-
-
Method Details
-
setMeasured
public void setMeasured(boolean measured) Set by the server once it knows whether it records metrics. -
bind
Takes the measuring and tracing of the server that runs this scheduler. Called by the generated application before it starts the scheduler. -
cron
-
fixedRate
-
fixedDelay
-
start
public void start()Starts the timetable. -
stop
public void stop(long waitMillis) Stops starting runs and waits up towaitMillisfor the ones in progress. -
trigger
Runs a job now, on its executor, whatever its schedule says. Answers false when no job has that name or its previous run is still going. -
describe
Every job and what has happened to it, for the management endpoint and MCP. -
getJobs
The registered jobs.
-