Michael Muesch
Michael Muesch

Reputation: 173

Quartz Cron String Understanding Issue

I currently have this quartz cron string 0 0/35 11-13 1/1 * ? *. Now what it generally means is Occurs every 1 day(s) every 35 minute(s) between 11 AM and 1 PM. At least from my understanding that is what it means. Though when I look at possible run times I get these.

That does not make sense to me. It seems to reset on the hour. Is there anyway for this not to occur? I would like the job to run at 11AM, then 11:35AM and then 12:10PM not 12PM.

Any and all help would be greatly appreciated.

Upvotes: 2

Views: 321

Answers (1)

Shailesh Pratapwar
Shailesh Pratapwar

Reputation: 4224

Yes , this is the problem my colleagues encounters every now and then.

As per the documentation for Quartz scheduler ( and yes off-course, as per my understanding of Quartz till now :-p ), cron trigger will be set to fire at "every 35th minute of the hour" and not "every 35th minute in a day".

For your requirement you should use a simple-trigger .

    Date firetime=null; //initialize to Your start time of trigger "11.00am"
            Date endtime=null; // initialize to Your end time of trigger "1.00pm"
    Trigger tr1 = TriggerBuilder
            .newTrigger()
            .startAt(firetime)
                            .endAt(endtime)
            .withIdentity("First Trigger", "First Group")
            .withSchedule(
                    SimpleScheduleBuilder.simpleSchedule()
                            .withIntervalInMinutes(35)
            ).build();

And use another trigger to schedule this trigger daily.:-)

Upvotes: 4

Related Questions