cron job between 8am and 8pm 4 times at specified intervals of time

2.4k views Asked by At

i need to run a job 'x' times a day. job timing is every (say 'y' hours) between 8am and 8pm. i read the documentation of cron between could not figure out how to place the "between times". any suggestion or a good tutorial should be really helpful.i could figure out this much.

Found this in a tutorial. I believe this will serve the requierment

SimpleTrigger simpleTrigger = new SimpleTrigger("simpleTrigger", "triggerGroup-s1");
            simpleTrigger.setStartTime(d);
            simpleTrigger.setRepeatInterval(1000*60*60*24);
            simpleTrigger.setRepeatCount(15);
                simpleTrigger.setEndTime(new Date(ctime + 60000L));
            simpleTrigger.setPriority(10);
            scheduler.scheduleJob(jobDetail, simpleTrigger);
                    scheduler.start();

how could i modify the expression to serve my purpose.

2

There are 2 answers

0
Carl Norum On BEST ANSWER

You have a * in your example where you need to put the start/end hours:

0 8-20/y * * *

Where you replace y with the number of hours you want between runs should be fine. If you have some strange time like "1 hour and 15 minutes between runs", it's going to be a pain - probably just easier to calculate each time and enter it explicitly.

0
Piotr Findeisen On

I don't know you can express this in cron expression. However, you can use multiple Quartz triggers to serve this purpose.