Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

@Retention(CLASS) @Target({METHOD})

public @interface Scheduled

Runs this method of a bean on a schedule.

Exactly one of cron, fixedRate or fixedDelay (or their String forms) must be given. The method takes no arguments.

A literal cron expression is parsed by the build, which writes its fields into the entry point as bit masks and refuses a malformed one: an expression nobody noticed was wrong otherwise fires never, or every second. One that reads configuration (${report.cron}) is parsed once at start-up instead.

The format is Spring’s six fields – second, minute, hour, day of month, month, day of week – plus the @yearly, @monthly, @weekly, @daily and @hourly macros:

@Scheduled(cron = "0 */15 * * * MON-FRI")
public void refresh() { ... }

Several instances of one server each run every job. lock makes a job run on one of them at a time, through a row in the database.

Methods

public abstract String cron() default ""A cron expression, or ${key} to read one from configuration.
public abstract String zone() default ""The time zone the cron expression is read in: a zone ID such as Europe/Berlin, a fixed offset such as +02:00, or UTC.
public abstract long fixedRate() default -1LMilliseconds between the starts of consecutive runs.
public abstract long fixedDelay() default -1LMilliseconds between the end of one run and the start of the next.
public abstract long initialDelay() default -1LMilliseconds before the first run of a fixed-rate or fixed-delay job.
public abstract String fixedRateString() default ""fixedRate as text, which may read configuration.
public abstract String fixedDelayString() default ""fixedDelay as text, which may read configuration.
public abstract String initialDelayString() default ""initialDelay as text, which may read configuration.
public abstract ThreadKind thread() default ThreadKind.PLATFORMWhich kind of thread runs it.
public abstract String executor() default ""The executor to run on.
public abstract String lock() default ""A lock name.
public abstract long lockAtMostFor() default -1LHow long a claimed lock is held at most, in milliseconds, so an instance that dies mid-run does not hold it for good.

Method details

cron

public abstract String cron() default ""
A cron expression, or ${key} to read one from configuration.

zone

public abstract String zone() default ""
The time zone the cron expression is read in: a zone ID such as Europe/Berlin, a fixed offset such as +02:00, or UTC. Empty means UTC, which is what a server should keep its clock in anyway.

fixedRate

public abstract long fixedRate() default -1L
Milliseconds between the starts of consecutive runs.

fixedDelay

public abstract long fixedDelay() default -1L
Milliseconds between the end of one run and the start of the next.

initialDelay

public abstract long initialDelay() default -1L
Milliseconds before the first run of a fixed-rate or fixed-delay job.

fixedRateString

public abstract String fixedRateString() default ""
fixedRate as text, which may read configuration.

fixedDelayString

public abstract String fixedDelayString() default ""
fixedDelay as text, which may read configuration.

initialDelayString

public abstract String initialDelayString() default ""
initialDelay as text, which may read configuration.

thread

public abstract ThreadKind thread() default ThreadKind.PLATFORM
Which kind of thread runs it.

executor

public abstract String executor() default ""
The executor to run on. Empty means scheduling.

lock

public abstract String lock() default ""
A lock name. When set, a run first claims the named row in the cn1_scheduler_lock table and is skipped if another instance holds it. Needs a database.

lockAtMostFor

public abstract long lockAtMostFor() default -1L
How long a claimed lock is held at most, in milliseconds, so an instance that dies mid-run does not hold it for good. Zero or less means ten minutes.