CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-quartz-scheduler--quartz

Quartz Enterprise Job Scheduler - A richly featured, open source job scheduling library that can be integrated within virtually any Java application

Pending
Overview
Eval results
Files

schedule-builders.mddocs/

Schedule Builders

Fluent builders for creating different types of schedules in Quartz. Schedule builders provide type-safe, readable ways to configure trigger schedules including simple intervals, cron expressions, calendar-based intervals, and daily time intervals.

Capabilities

ScheduleBuilder Base Class

Abstract base class for all schedule builders providing common structure.

/**
 * Base class for all schedule builders
 */
abstract class ScheduleBuilder<T extends Trigger> {
    /**
     * Build the trigger instance with this schedule
     * @return configured trigger instance
     */
    protected abstract MutableTrigger build();
}

SimpleScheduleBuilder Class

Builder for simple interval-based schedules with regular repetition patterns.

/**
 * Builder for SimpleTrigger schedules with interval-based repetition
 */
class SimpleScheduleBuilder extends ScheduleBuilder<SimpleTrigger> {
    /**
     * Create a simple schedule builder
     * @return new builder instance
     */
    static SimpleScheduleBuilder simpleSchedule();
    
    /**
     * Create builder for repeating every minute forever
     * @return configured builder
     */
    static SimpleScheduleBuilder repeatMinutelyForever();
    
    /**
     * Create builder for repeating every N minutes forever
     * @param minutes interval in minutes
     * @return configured builder
     */
    static SimpleScheduleBuilder repeatMinutelyForever(int minutes);
    
    /**
     * Create builder for repeating every second forever
     * @return configured builder
     */
    static SimpleScheduleBuilder repeatSecondlyForever();
    
    /**
     * Create builder for repeating every N seconds forever
     * @param seconds interval in seconds
     * @return configured builder
     */
    static SimpleScheduleBuilder repeatSecondlyForever(int seconds);
    
    /**
     * Create builder for repeating every hour forever
     * @return configured builder
     */
    static SimpleScheduleBuilder repeatHourlyForever();
    
    /**
     * Create builder for repeating every N hours forever
     * @param hours interval in hours
     * @return configured builder
     */
    static SimpleScheduleBuilder repeatHourlyForever(int hours);
    
    /**
     * Set the repeat interval in milliseconds
     * @param intervalInMillis interval in milliseconds
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withIntervalInMilliseconds(long intervalInMillis);
    
    /**
     * Set the repeat interval in seconds
     * @param intervalInSeconds interval in seconds
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withIntervalInSeconds(int intervalInSeconds);
    
    /**
     * Set the repeat interval in minutes
     * @param intervalInMinutes interval in minutes
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withIntervalInMinutes(int intervalInMinutes);
    
    /**
     * Set the repeat interval in hours
     * @param intervalInHours interval in hours
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withIntervalInHours(int intervalInHours);
    
    /**
     * Set the number of times to repeat (0 = fire once)
     * @param triggerRepeatCount number of repeats
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withRepeatCount(int triggerRepeatCount);
    
    /**
     * Repeat forever (until end time or trigger removal)
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder repeatForever();
    
    /**
     * Set misfire instruction to ignore misfires
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
    
    /**
     * Set misfire instruction to fire trigger immediately when misfire is detected
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withMisfireHandlingInstructionFireNow();
    
    /**
     * Set misfire instruction to reschedule with existing repeat count
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withMisfireHandlingInstructionNowWithExistingCount();
    
    /**
     * Set misfire instruction to reschedule with remaining repeat count
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withMisfireHandlingInstructionNowWithRemainingCount();
    
    /**
     * Set misfire instruction to reschedule at next scheduled time with existing count
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withMisfireHandlingInstructionNextWithExistingCount();
    
    /**
     * Set misfire instruction to reschedule at next scheduled time with remaining count
     * @return this builder for method chaining
     */
    SimpleScheduleBuilder withMisfireHandlingInstructionNextWithRemainingCount();
}

Usage Examples:

// Basic simple schedules
Trigger everyMinute = newTrigger()
    .withSchedule(repeatMinutelyForever())
    .build();

Trigger every30Seconds = newTrigger()
    .withSchedule(repeatSecondlyForever(30))
    .build();

Trigger every2Hours = newTrigger()
    .withSchedule(repeatHourlyForever(2))
    .build();

// Custom intervals
Trigger customInterval = newTrigger()
    .withSchedule(simpleSchedule()
        .withIntervalInMilliseconds(45000) // 45 seconds
        .withRepeatCount(10)               // Fire 11 times total
        .withMisfireHandlingInstructionFireNow())
    .build();

// Limited repetition
Trigger limitedRepeats = newTrigger()
    .withSchedule(simpleSchedule()
        .withIntervalInMinutes(15)
        .withRepeatCount(5)  // Fire 6 times total (initial + 5 repeats)
        .withMisfireHandlingInstructionNextWithRemainingCount())
    .build();

// One-time execution
Trigger oneTime = newTrigger()
    .withSchedule(simpleSchedule()
        .withRepeatCount(0)) // Fire only once
    .build();

// Static imports for cleaner syntax
import static org.quartz.SimpleScheduleBuilder.*;

Trigger clean = newTrigger()
    .withSchedule(repeatMinutelyForever(5))
    .build();

CronScheduleBuilder Class

Builder for cron expression-based schedules supporting complex time patterns.

/**
 * Builder for CronTrigger schedules using cron expressions
 */
class CronScheduleBuilder extends ScheduleBuilder<CronTrigger> {
    /**
     * Create a cron schedule from expression string
     * @param cronExpression the cron expression
     * @return new builder instance
     * @throws ParseException if cron expression is invalid
     */
    static CronScheduleBuilder cronSchedule(String cronExpression);
    
    /**
     * Create a cron schedule from CronExpression object
     * @param cronExpression the cron expression object
     * @return new builder instance
     */
    static CronScheduleBuilder cronSchedule(CronExpression cronExpression);
    
    /**
     * Create schedule for daily execution at specific hour and minute
     * @param hour hour of day (0-23)
     * @param minute minute of hour (0-59)
     * @return configured builder for daily execution
     */
    static CronScheduleBuilder dailyAtHourAndMinute(int hour, int minute);
    
    /**
     * Create schedule for weekly execution on specific day, hour, and minute
     * @param dayOfWeek day of week (1=Sunday, 7=Saturday)
     * @param hour hour of day (0-23)
     * @param minute minute of hour (0-59)
     * @return configured builder for weekly execution
     */
    static CronScheduleBuilder weeklyOnDayAndHourAndMinute(int dayOfWeek, int hour, int minute);
    
    /**
     * Create schedule for monthly execution on specific day, hour, and minute
     * @param dayOfMonth day of month (1-31)
     * @param hour hour of day (0-23)
     * @param minute minute of hour (0-59)
     * @return configured builder for monthly execution
     */
    static CronScheduleBuilder monthlyOnDayAndHourAndMinute(int dayOfMonth, int hour, int minute);
    
    /**
     * Set the time zone for cron expression evaluation
     * @param timezone the time zone
     * @return this builder for method chaining
     */
    CronScheduleBuilder inTimeZone(TimeZone timezone);
    
    /**
     * Set misfire instruction to ignore misfires
     * @return this builder for method chaining
     */
    CronScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
    
    /**
     * Set misfire instruction to fire once when misfire is detected
     * @return this builder for method chaining
     */
    CronScheduleBuilder withMisfireHandlingInstructionFireAndProceed();
    
    /**
     * Set misfire instruction to do nothing on misfire
     * @return this builder for method chaining
     */
    CronScheduleBuilder withMisfireHandlingInstructionDoNothing();
}

Usage Examples:

// Basic cron schedules
Trigger dailyAt9AM = newTrigger()
    .withSchedule(cronSchedule("0 0 9 * * ?"))
    .build();

Trigger everyWeekday9AM = newTrigger()
    .withSchedule(cronSchedule("0 0 9 ? * MON-FRI"))
    .build();

Trigger every15Minutes = newTrigger()
    .withSchedule(cronSchedule("0 */15 * * * ?"))
    .build();

// Using convenience methods
Trigger dailyNoon = newTrigger()
    .withSchedule(dailyAtHourAndMinute(12, 0))
    .build();

Trigger mondayMorning = newTrigger()
    .withSchedule(weeklyOnDayAndHourAndMinute(2, 9, 30)) // Monday 9:30 AM
    .build();

Trigger monthlyFirst = newTrigger()
    .withSchedule(monthlyOnDayAndHourAndMinute(1, 0, 0)) // 1st of month midnight
    .build();

// With timezone and misfire handling
Trigger cronWithTimezone = newTrigger()
    .withSchedule(cronSchedule("0 0 12 * * ?")
        .inTimeZone(TimeZone.getTimeZone("America/New_York"))
        .withMisfireHandlingInstructionFireAndProceed())
    .build();

// Complex cron expressions
Trigger businessHours = newTrigger()
    .withSchedule(cronSchedule("0 */30 9-17 ? * MON-FRI")) // Every 30 min, 9-5, weekdays
    .build();

Trigger quarterlyReport = newTrigger()
    .withSchedule(cronSchedule("0 0 9 1 1,4,7,10 ?")) // 9 AM on Jan 1, Apr 1, Jul 1, Oct 1
    .build();

// Static imports for cleaner syntax
import static org.quartz.CronScheduleBuilder.*;

Trigger clean = newTrigger()
    .withSchedule(dailyAtHourAndMinute(14, 30))
    .build();

CalendarIntervalScheduleBuilder Class

Builder for calendar-based interval schedules that respect calendar boundaries.

/**
 * Builder for CalendarIntervalTrigger schedules with calendar-aware intervals
 */
class CalendarIntervalScheduleBuilder extends ScheduleBuilder<CalendarIntervalTrigger> {
    /**
     * Create a calendar interval schedule builder
     * @return new builder instance
     */
    static CalendarIntervalScheduleBuilder calendarIntervalSchedule();
    
    /**
     * Set the interval for the schedule
     * @param interval the interval value
     * @param unit the interval unit (SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR)
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withInterval(int interval, DateBuilder.IntervalUnit unit);
    
    /**
     * Set interval in seconds
     * @param intervalInSeconds interval in seconds
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withIntervalInSeconds(int intervalInSeconds);
    
    /**
     * Set interval in minutes
     * @param intervalInMinutes interval in minutes
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withIntervalInMinutes(int intervalInMinutes);
    
    /**
     * Set interval in hours
     * @param intervalInHours interval in hours
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withIntervalInHours(int intervalInHours);
    
    /**
     * Set interval in days
     * @param intervalInDays interval in days
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withIntervalInDays(int intervalInDays);
    
    /**
     * Set interval in weeks
     * @param intervalInWeeks interval in weeks
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withIntervalInWeeks(int intervalInWeeks);
    
    /**
     * Set interval in months
     * @param intervalInMonths interval in months
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withIntervalInMonths(int intervalInMonths);
    
    /**
     * Set interval in years
     * @param intervalInYears interval in years
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withIntervalInYears(int intervalInYears);
    
    /**
     * Preserve hour of day across daylight saving time changes
     * @param preserveHourOfDayAcrossDaylightSavings true to preserve hour
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder preserveHourOfDayAcrossDaylightSavings(boolean preserveHourOfDayAcrossDaylightSavings);
    
    /**
     * Skip day if hour does not exist due to daylight saving time
     * @param skipDayIfHourDoesNotExist true to skip day
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder skipDayIfHourDoesNotExist(boolean skipDayIfHourDoesNotExist);
    
    /**
     * Set the time zone for calendar calculations
     * @param timezone the time zone
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder inTimeZone(TimeZone timezone);
    
    /**
     * Set misfire instruction to ignore misfires
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
    
    /**
     * Set misfire instruction to fire once when misfire is detected
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withMisfireHandlingInstructionFireAndProceed();
    
    /**
     * Set misfire instruction to do nothing on misfire
     * @return this builder for method chaining
     */
    CalendarIntervalScheduleBuilder withMisfireHandlingInstructionDoNothing();
}

Usage Examples:

// Basic calendar intervals
Trigger daily = newTrigger()
    .withSchedule(calendarIntervalSchedule()
        .withIntervalInDays(1))
    .build();

Trigger weekly = newTrigger()
    .withSchedule(calendarIntervalSchedule()
        .withIntervalInWeeks(1))
    .build();

Trigger monthly = newTrigger()
    .withSchedule(calendarIntervalSchedule()
        .withIntervalInMonths(1))
    .build();

// Calendar-aware scheduling with DST handling
Trigger dstAware = newTrigger()
    .withSchedule(calendarIntervalSchedule()
        .withIntervalInDays(1)
        .preserveHourOfDayAcrossDaylightSavings(true)
        .skipDayIfHourDoesNotExist(true)
        .inTimeZone(TimeZone.getTimeZone("America/New_York")))
    .build();

// Quarterly reports (every 3 months)
Trigger quarterly = newTrigger()
    .withSchedule(calendarIntervalSchedule()
        .withInterval(3, DateBuilder.IntervalUnit.MONTH)
        .withMisfireHandlingInstructionFireAndProceed())
    .build();

// Business day intervals (every weekday)
Trigger businessDaily = newTrigger()
    .withSchedule(calendarIntervalSchedule()
        .withIntervalInDays(1))
    .modifiedByCalendar("businessDaysOnly") // Requires business day calendar
    .build();

// Static imports for cleaner syntax
import static org.quartz.CalendarIntervalScheduleBuilder.*;

Trigger clean = newTrigger()
    .withSchedule(calendarIntervalSchedule().withIntervalInDays(7))
    .build();

DailyTimeIntervalScheduleBuilder Class

Builder for daily time interval schedules that fire during specific time periods on selected days.

/**
 * Builder for DailyTimeIntervalTrigger schedules with time-of-day constraints
 */
class DailyTimeIntervalScheduleBuilder extends ScheduleBuilder<DailyTimeIntervalTrigger> {
    /**
     * Create a daily time interval schedule builder
     * @return new builder instance
     */
    static DailyTimeIntervalScheduleBuilder dailyTimeIntervalSchedule();
    
    /**
     * Set which days of the week the trigger should fire
     * @param daysOfWeek set of day numbers (1=Sunday, 2=Monday, ..., 7=Saturday)
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder onDaysOfTheWeek(Set<Integer> daysOfWeek);
    
    /**
     * Set which days of the week the trigger should fire
     * @param daysOfWeek array of day numbers
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder onDaysOfTheWeek(Integer... daysOfWeek);
    
    /**
     * Set trigger to fire only on Monday through Friday
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder onMondayThroughFriday();
    
    /**
     * Set trigger to fire only on Saturday and Sunday
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder onSaturdayAndSunday();
    
    /**
     * Set trigger to fire every day of the week
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder onEveryDay();
    
    /**
     * Set the start time of day
     * @param timeOfDay the start time
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder startingDailyAt(TimeOfDay timeOfDay);
    
    /**
     * Set the end time of day
     * @param timeOfDay the end time
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder endingDailyAt(TimeOfDay timeOfDay);
    
    /**
     * Set the firing interval
     * @param interval the interval value
     * @param unit the interval unit (SECOND, MINUTE, HOUR only)
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withInterval(int interval, DateBuilder.IntervalUnit unit);
    
    /**
     * Set interval in seconds
     * @param intervalInSeconds interval in seconds
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withIntervalInSeconds(int intervalInSeconds);
    
    /**
     * Set interval in minutes
     * @param intervalInMinutes interval in minutes
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withIntervalInMinutes(int intervalInMinutes);
    
    /**
     * Set interval in hours
     * @param intervalInHours interval in hours
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withIntervalInHours(int intervalInHours);
    
    /**
     * Set the repeat count (number of additional firings after the first)
     * @param repeatCount repeat count or REPEAT_INDEFINITELY
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withRepeatCount(int repeatCount);
    
    /**
     * Set the time zone for time calculations
     * @param timezone the time zone
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder inTimeZone(TimeZone timezone);
    
    /**
     * Set misfire instruction to ignore misfires
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
    
    /**
     * Set misfire instruction to fire once when misfire is detected
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withMisfireHandlingInstructionFireAndProceed();
    
    /**
     * Set misfire instruction to do nothing on misfire
     * @return this builder for method chaining
     */
    DailyTimeIntervalScheduleBuilder withMisfireHandlingInstructionDoNothing();
}

Usage Examples:

// Business hours monitoring (every 15 minutes, 9 AM - 5 PM, weekdays)
Trigger businessHours = newTrigger()
    .withSchedule(dailyTimeIntervalSchedule()
        .onMondayThroughFriday()
        .startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0))
        .endingDailyAt(TimeOfDay.hourAndMinuteOfDay(17, 0))
        .withIntervalInMinutes(15))
    .build();

// Weekend maintenance (every 2 hours on weekends)
Trigger weekendMaintenance = newTrigger()
    .withSchedule(dailyTimeIntervalSchedule()
        .onSaturdayAndSunday()
        .withIntervalInHours(2))
    .build();

// Custom days and times
Set<Integer> customDays = Set.of(2, 4, 6); // Monday, Wednesday, Friday
Trigger customSchedule = newTrigger()
    .withSchedule(dailyTimeIntervalSchedule()
        .onDaysOfTheWeek(customDays)
        .startingDailyAt(TimeOfDay.hourMinuteAndSecondOfDay(8, 30, 0))
        .endingDailyAt(TimeOfDay.hourMinuteAndSecondOfDay(18, 30, 0))
        .withInterval(30, DateBuilder.IntervalUnit.MINUTE)
        .withRepeatCount(20)) // Limited repeats per day
    .build();

// High frequency during trading hours
Trigger tradingHours = newTrigger()
    .withSchedule(dailyTimeIntervalSchedule()
        .onMondayThroughFriday()
        .startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 30)) // Market open
        .endingDailyAt(TimeOfDay.hourAndMinuteOfDay(16, 0))   // Market close
        .withIntervalInSeconds(30)
        .inTimeZone(TimeZone.getTimeZone("America/New_York"))
        .withMisfireHandlingInstructionFireAndProceed())
    .build();

// Static imports for cleaner syntax
import static org.quartz.DailyTimeIntervalScheduleBuilder.*;

Trigger clean = newTrigger()
    .withSchedule(dailyTimeIntervalSchedule()
        .onEveryDay()
        .withIntervalInHours(1))
    .build();

TimeOfDay Class

Utility class for representing specific times of day used with DailyTimeIntervalTrigger.

/**
 * Represents a time of day (hour, minute, second)
 */
class TimeOfDay implements Serializable {
    /**
     * Create time from hour and minute (second = 0)
     * @param hour hour of day (0-23)
     * @param minute minute of hour (0-59)
     * @return TimeOfDay instance
     */
    static TimeOfDay hourAndMinuteOfDay(int hour, int minute);
    
    /**
     * Create time from hour, minute, and second
     * @param hour hour of day (0-23)
     * @param minute minute of hour (0-59)
     * @param second second of minute (0-59)
     * @return TimeOfDay instance
     */
    static TimeOfDay hourMinuteAndSecondOfDay(int hour, int minute, int second);
    
    /**
     * Get the hour component
     * @return hour (0-23)
     */
    int getHour();
    
    /**
     * Get the minute component
     * @return minute (0-59)
     */
    int getMinute();
    
    /**
     * Get the second component
     * @return second (0-59)
     */
    int getSecond();
    
    /**
     * Check if this time is before another time
     * @param timeOfDay the other time
     * @return true if this time is before the other
     */
    boolean before(TimeOfDay timeOfDay);
    
    /**
     * Check if this time is after another time
     * @param timeOfDay the other time
     * @return true if this time is after the other
     */
    boolean after(TimeOfDay timeOfDay);
}

Usage Examples:

// Creating TimeOfDay instances
TimeOfDay morning = TimeOfDay.hourAndMinuteOfDay(9, 0);   // 9:00 AM
TimeOfDay evening = TimeOfDay.hourAndMinuteOfDay(17, 30); // 5:30 PM
TimeOfDay precise = TimeOfDay.hourMinuteAndSecondOfDay(12, 30, 45); // 12:30:45 PM

// Using in schedules
Trigger timeConstrained = newTrigger()
    .withSchedule(dailyTimeIntervalSchedule()
        .startingDailyAt(morning)
        .endingDailyAt(evening)
        .withIntervalInMinutes(30))
    .build();

// Time comparisons
if (morning.before(evening)) {
    System.out.println("Morning comes before evening");
}

Install with Tessl CLI

npx tessl i tessl/maven-org-quartz-scheduler--quartz

docs

calendar-management.md

core-scheduling.md

enterprise-features.md

exception-handling.md

index.md

job-management.md

listeners-events.md

matcher-framework.md

persistence-storage.md

schedule-builders.md

trigger-management.md

utilities-helpers.md

tile.json