Quartz Cron trigger to run every 2nd day
java, quartz-scheduler
Solution
CronTrigger cronTrigger = newTrigger()
.withIdentity("trigger1", "testJob")
.startAt(startDate)
.withSchedule(
CronScheduleBuilder.cronSchedule(" * * * */2 * ?")
.withMisfireHandlingInstructionDoNothing()
).build();
So you need to replace `1/2` with `*/2`. Here `*` means each day and `*/2` mean every second day.
UPDATE
`CronTrigger` can not be use to run every 2 days interval as it will always start at 1st day of every month even though last jab execution was on 31, it will run at 1st day of month instead if 2nd day of month. You can set it in to run after 48 hours in place of every 2 days.
Please look if this will help you:
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startAt(tomorrowAt(15, 0, 0) // first fire time 15:00:00 tomorrow
.withSchedule(
simpleSchedule()
.withIntervalInHours(2 * 24) // interval is actually set at 48 hours' worth of milliseconds
.repeatForever()
).build();
for more information please refer This link
Problem
I want to make my cron execute job every 2nd day. So if i execute job at 25th May, it will run at 25th, 27th, 29th, 31th, 2nd June, 4th June .. but the issue is, after the end of 31th May, the cron will reset and start running at 1st June, 3rd June, 5th June ... instead of 2nd June, 4th June .. below is my code.. ``` CronTrigger cronTrigger = newTrigger() .withIdentity("trigger1", "testJob") .startAt(startDate) .withSchedule(CronScheduleBuilder.cronSchedule( * * * 1/2 * ?") .withMisfireHandlingInstructionDoNothing()) .build(); ```