Pratik Roy
Pratik Roy

Reputation: 734

How to fire a trigger every 30 seconds from 2 pm to 11 pm in quartz using Java?

I am using this statement -

trigger2 = TriggerBuilder.newTrigger()
                         .withIdentity("abc", "group1")
                         .withSchedule(CronScheduleBuilder
                                             .cronSchedule("0/30 0 14-23 * * ?"))
                         .build();

Somehow the trigger is fired at 2 pm, 2:00:30 pm and no more. What is the problem?

Upvotes: 0

Views: 856

Answers (2)

Olimpiu POP
Olimpiu POP

Reputation: 5067

From quartz scheduler documentation I extracted the following example:

Job #1 is scheduled to run every 20 seconds

JobDetail job = new JobDetail("job1", "group1", SimpleJob.class);
CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1", "group1", "0/20 * * * * ?");
sched.addJob(job, true);

Adapting to your situation it should go like this:

CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1", "group1", "0/30 * 14-23 * * ?");

Upvotes: 0

amudhan3093
amudhan3093

Reputation: 750

The problem is that you have put 0 in the minute field.So it fires only at 2:00. Try

 trigger2 = TriggerBuilder
                    .newTrigger()
                    .withIdentity("abc", "group1")
                    .withSchedule(
                      CronScheduleBuilder.cronSchedule("0/30 * 14-23 * * ?"))
                    .build();

Upvotes: 3

Related Questions