Search code examples
cronquartz-schedulercronexpression

Configure Quartz for interval and different starting hours


I've been looking for this for a while now, but I didn't find a way to do what I want.

I have a Web Page in which a user can plan some actions during a week. For example: On monday morning, from 8:00 to 10:00, do this... On tuesday afternoon, from 1:30 to 2:00, do that...

Well, I would like that my Java program automatically launch the actions for the periods that the user selected. And, during these time intervals, repeat the action every X minutes. (Should be configurable)

What I thought was setting up Quartz with Cron scheduler. However, I don't know how to handle half hours...

More precisely:

This will work for my first example (repeat every 5 minutes between 8 to 10):

0 0/5 8-10 * * MON

But how to handle the second example? (Starting at 1:30 but repeat the action every 5 minutes??)

Thanks !

Philippe


Solution

  • actually I found an answer to my needs: DailyTimeIntervalScheduleBuilder !

    Here is an example for answer my need:

    DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule()
                                                                    .startingDailyAt(new TimeOfDay(13, 30, 0))
                                                                    .endingDailyAt(new TimeOfDay(14, 0, 0))
                                                                    .onDaysOfTheWeek(1)
                                                                    .withIntervalInMinutes(5);
    

    Problem solved Philippe