# Quartz — Enterprise Job Scheduling for Java > Feature-rich open-source job scheduling library for Java that supports cron expressions, clustering, and persistent job stores. ## Install Save in your project root: # Quartz — Enterprise Job Scheduling for Java ## Quick Use ```java SchedulerFactory sf = new StdSchedulerFactory(); Scheduler scheduler = sf.getScheduler(); JobDetail job = newJob(MyJob.class) .withIdentity("myJob").build(); Trigger trigger = newTrigger() .withSchedule(cronSchedule("0 0/5 * * * ?")).build(); scheduler.scheduleJob(job, trigger); scheduler.start(); ``` ## Introduction Quartz is a widely adopted open-source job scheduling library for Java applications. It lets developers define jobs as simple Java classes and schedule them using cron expressions, intervals, or calendar-based triggers. Quartz can run embedded within an application server or as a standalone process, and supports clustering across multiple nodes with JDBC-backed job stores for persistence and failover. ## What Quartz Does - Schedules jobs using cron expressions, fixed intervals, or calendar rules - Persists job definitions and triggers to a relational database via JDBC - Supports clustered execution where multiple scheduler instances share work - Provides listeners and plugins for job lifecycle events, logging, and history - Handles misfired triggers with configurable recovery policies ## Architecture Overview A Quartz Scheduler manages a JobStore that holds job definitions and trigger states. The RAMJobStore keeps everything in memory for fast single-node use, while the JDBCJobStore persists to a database for durability and clustering. A thread pool of configurable size executes jobs when their triggers fire. In clustered mode, multiple Scheduler instances use database row-level locking to coordinate trigger ownership, ensuring each job fires exactly once across the cluster. ## Self-Hosting & Configuration - Add `org.quartz-scheduler:quartz` to your Maven or Gradle dependencies - Configure via `quartz.properties` with thread pool size, job store type, and data source - Define jobs by implementing the `org.quartz.Job` interface - Build triggers with the fluent `TriggerBuilder` and `CronScheduleBuilder` APIs - For clustering, set `org.quartz.jobStore.isClustered = true` and point all nodes at the same database ## Key Features - Cron expressions support second-level granularity beyond standard Unix cron - JDBC job store provides persistence across application restarts - Built-in clustering with automatic failover and load balancing - Misfire handling policies let you skip, fire immediately, or reschedule missed triggers - Calendar exclusions can block job execution on holidays or maintenance windows ## Comparison with Similar Tools - **Spring @Scheduled** — simple annotation-based cron for Spring apps; Quartz adds persistence and clustering - **Temporal** — durable workflow orchestration; Quartz is lighter for simple job scheduling - **Celery Beat** — Python periodic task scheduler; Quartz serves the Java/JVM ecosystem - **Hangfire** — .NET background jobs; Quartz is the Java equivalent with JDBC stores - **Airflow** — DAG-based workflow orchestration; Quartz handles individual recurring jobs ## FAQ **Q: Can Quartz run in a Spring Boot application?** A: Yes. Spring Boot has built-in auto-configuration for Quartz via the `spring-boot-starter-quartz` dependency. **Q: How does Quartz handle a missed job trigger?** A: Configurable misfire instructions let you fire immediately, discard the missed run, or reschedule to the next valid time. **Q: Does Quartz support distributed execution across servers?** A: Yes. Configure JDBC job store with clustering enabled and all nodes sharing the same database. **Q: What databases does the JDBC job store support?** A: Quartz provides SQL scripts for PostgreSQL, MySQL, Oracle, SQL Server, H2, and other databases. ## Sources - https://github.com/quartz-scheduler/quartz - https://www.quartz-scheduler.org/documentation/ --- Source: https://tokrepo.com/en/workflows/asset-6369fc9f Author: AI Open Source