Question

Reading the quartz 2.1 documentation doesn't completely answer my question: - How do I setup a Trigger to continuously start a job every 20 minutes only between 09:00 to 12:00 daily?

maybe with a combination of startAt and endAt?

trigger = newTrigger()
    .withIdentity("trigger3", "group1")
    .startAt(tomorrowAt(15, 0, 0)  // first fire time 15:00:00 tomorrow
    .withSchedule(simpleSchedule()
            .withIntervalInHours(24) // interval is actually set at 24 hours' worth of milliseconds
            .repeatForever())
    .build()

http://quartz-scheduler.org/documentation/quartz-2.1.x/cookbook/DailyTrigger

Was it helpful?

Solution

You could use Cron expressions. Tutorial here: http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06

CronTrigger Example 2 - an expression to create a trigger that fires every 5 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:05:10 am, etc.).

"10 0/5 * * * ?"

There are also sites helping to create Cron expressions http://www.abunchofutils.com/utils/developer/cron-expression-helper/

The expression */20 9-11 * * * triggers every 20 minutes between 9 and 12, but it won't trigger at 12:00.


Or you can use a DailyTimeIntervalScheduleBuilder:

Trigger trigger = DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule()
        .onEveryDay()
        .startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0))
        .endingDailyAt(TimeOfDay.hourAndMinuteOfDay(12, 0))
        .withIntervalInMinutes(20)
        .build();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top