Quartz Core

Repeated Tasks

Quartz Framework supports declarative scheduling of repeated tasks using the @RepeatedTask annotation. This allows developers to define periodic logic in a clean, annotation-driven way without managing scheduling manually.


Enabling Repeated Tasks

To activate support for repeated task discovery, annotate any Quartz-managed bean (including the main class) with:

@EnableRepeatedTasks
@QuartzApplication
public class MyPlugin extends SpigotPlugin { ... }

This enables the internal TaskInitializationContextBootstrapper, which scans all beans for methods annotated with @RepeatedTask and schedules them automatically after the context is loaded.

Usage

Annotate any method inside an injectable or other context-managed bean with @RepeatedTask:

@RepeatedTask(fixedDelay = 5, timeUnit = TimeUnit.SECONDS)
public void tick() {
    log.info("Running every 5 seconds");
}

You can use either fixed delays or cron expressions, depending on your use case.


Available Options

AttributeDescription
fixedDelayDelay between executions (default: -1 = disabled)
initialDelayOptional delay before first execution
timeUnitUnit of time for fixed delays (default: MILLISECONDS)
cronCron expression (default: * * * * *)
zoneIdTime zone for cron execution (default: system time zone or "default")
executorNameExecutor pool name to target (default: default)

If fixedDelay is set to -1, Quartz will use the cron strategy to determine execution.


Cron-based Execution

@RepeatedTask(cron = "0 */5 * * * *")
public void everyFiveMinutes() {
    log.info("Triggered on schedule");
}

Lifecycle Management

When @EnableRepeatedTasks is active:

All @RepeatedTask methods are scheduled after the DI context is fully loaded (@ContextLoads)

All executors are gracefully shutdown during @PreDestroy phase

Previous
Task & Scheduling