java - How do you execute cron job every 5 minutes? -


jobdetail job1 = jobbuilder.newjob(firstjob.class).withidentity("job1", "group1").build();          trigger trigger1 = triggerbuilder.newtrigger().withidentity("crontrigger1", "group1")                 .withschedule(cronschedulebuilder.cronschedule("*/10 * * * * ?")).build();          scheduler scheduler1 = new stdschedulerfactory().getscheduler();         scheduler1.start();         scheduler1.schedulejob(job1, trigger1);          jobdetail job2 = jobbuilder.newjob(secondjob.class).withidentity("job2", "group2").build();          trigger trigger2 = triggerbuilder.newtrigger().withidentity("crontrigger2", "group2")                 .withschedule(cronschedulebuilder.cronschedule(new cronexpression("0/7 * * * * ?"))).build();          scheduler scheduler2 = new stdschedulerfactory().getscheduler();         scheduler2.start();         scheduler2.schedulejob(job2, trigger2);          thread.sleep(100000);          scheduler1.shutdown();         scheduler2.shutdown(); 

i trying execute cron job every 5 minutes of hour not executing on time. think time expression wrong.

how set time expression 1, 5 minute job , 2 1 hour job?

for job 1, 5 minute, can use:

*/5 * * * * ? 

because first field minutes. if specify * in field, runs every minutes. if specify */5 in 1st field, runs every 5 minutes shown above.

for job 2, 1 hour, can use:

0 */1 * * * 

because second field hours. if specify * in field, runs every hour. if specify */5 in 2nd field, runs every 5 hours shown above.

not related cron code seems missing pass expression thelostmind comment.

correct sentence job 1:

trigger trigger1 = triggerbuilder.newtrigger().withidentity("crontrigger1", "group1")                 .withschedule(cronschedulebuilder.cronschedule(new cronexpression("*/10 * * * * ?"))).build(); 

hope helps.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -