Skip to content

Core Concepts

frosxt edited this page Jan 20, 2026 · 1 revision

Core Concepts

Schedulers

The Scheduler is the main entry point. It manages a pool of worker threads and orchestrates task execution.

  • Thread Pool: Configurable size via SchedulerSpec.threadCount().
  • Time Source: Uses monotonic time (System.nanoTime()) for duration calculations to be immune to system clock shifts.
  • Lifecycle: Must be closed via close() to terminate worker threads.

Triggers

Triggers determine when a task runs.

  1. OnceTrigger: Fires a single time after a delay.
  2. FixedRateTrigger: Fires at regular intervals (e.g., every 5 minutes). If a task takes too long, subsequent executions may bunch up or be skipped depending on policy.
  3. FixedDelayTrigger: Fires after a fixed delay after the previous execution completes. Useful for preventing overlap.
  4. CronTrigger: Fires based on a calendar schedule (e.g., "Mondays at 9 AM").

Tasks

A task is simply a Runnable. Chronos wraps your runnable to provide:

  • History: Tracks run counts, success rates, and last execution times.
  • Safety: Catches exceptions to prevent thread death (configurable via ExecutionPolicy).
  • Resilience: Can automatically retry upon failure.
  • State: Tracks lifecycle states (SCHEDULED, RUNNING, COMPLETED, FAILED, CANCELLED).

Clone this wiki locally