Skip to content

Threading Model

frosxt edited this page Jan 20, 2026 · 1 revision

Threading Model

Chronos was designed with a simple but high-performance threading model. Understanding this model is key to configuring your scheduler correctly.

Worker Pool

Chronos uses a fixed-size pool of Platform Threads.

  • Configuration: Set via SchedulerSpec.builder().threadCount(N).
  • Behavior: All tasks (One-Shot, Fixed-Rate, Cron) share this same pool.
  • Isolation: Chronos isolates its internal loop from user tasks. The scheduler thread manages triggers, while the worker pool executes the user's Runnable.
Scheduler scheduler = Chronos.create(SchedulerSpec.builder()
    .threadCount(4) // 4 concurrent tasks allowed
    .build());

Best Practices

1. Avoid Blocking

Since the pool size is fixed, long-running blocking operations (e.g., synchronous HTTP calls with long timeouts, DB queries) can exhaust the worker threads.

  • Good: Short, CPU-bound tasks or non-blocking I/O.
  • Mitigation: If you must block, increase threadCount to accommodate the wait times, or offload the blocking work to a separate, dedicated ExecutorService.

2. Thread Naming

Chronos names threads using the prefix defined in configuration. This helps significantly with debugging and log analysis.

  • Default: chronos-worker-N
  • Custom:
.threadNamePrefix("payment-processor-")
// Threads will be: payment-processor-1, payment-processor-2, etc.

Virtual Threads

Chronos uses Platform Threads to ensure maximum compatibility with the broadest range of execution environments.

Clone this wiki locally