At work, I recently encountered Quartz CRON β a more powerful and flexible version of the classic UNIX CRON. Itβs mainly used in Java applications with the Quartz Scheduler, and I found it really useful for managing complex job schedules.
If youβre looking to understand the basics of CRON, check out my previous blog for a detailed explanation.
π§© Quartz CRON Syntax
Unlike UNIX CRON, which uses 5 fields, Quartz CRON has 7 fields, including seconds and an optional year field. Hereβs what it looks like:
ββββββββββββββ second (0 - 59)
β ββββββββββββ minute (0 - 59)
β β ββββββββββ hour (0 - 23)
β β β ββββββββ day of month (1 - 31)
β β β β ββββββ month (1 - 12 or JAN-DEC)
β β β β β ββββ day of week (1 - 7 or SUN-SAT)
β β β β β β ββ year (optional)
β β β β β β β
* * * * * * *
β Why Itβs Better
- Second-level precision: You can schedule jobs as frequently as every second.
- Optional year field: This makes it easy to add or omit year-based scheduling.
- Flexible day/week options: It supports advanced patterns like βfirst Monday of the monthβ or βlast day of the month.β
βοΈ Common Examples
0 0 12 * * ?
β Every day at 12 PM0 15 10 ? * MON-FRI
β 10:15 AM, Monday to Friday0 0/5 14 * * ?
β Every 5 minutes starting at 2 PM
β οΈ Quartz vs UNIX CRON
Quartz CRON extends the traditional format with:
- 7 fields instead of 5.
- Second-level precision.
- Special characters like
?
,L
,W
, and#
.
Happy Scheduling!