Quartz Scheduler for java- How to start work every 5 minutes

Friends, I use a quartz scheduler to run a task every 5 minutes, starting with the deployment and operation of the application, so I wrote the code as:

SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sche = sf.getScheduler(); JobDetail job = newJob(RomeJob.class).withIdentity("Id1", "Rome").build(); CronTrigger trigger = newTrigger().withIdentity("Id1Trigger", "Rome").withSchedule(cronSchedule("0 0/5 * * * ?")) .build(); sche.scheduleJob(job, trigger); sche.start(); 

But his work sometimes does not happen. Please tell me something is missing here?

+4
source share
3 answers

You have many ways for one of them to use a trigger constructor, for example,

 trigger = newTrigger() .withIdentity("mytrigger", "group1") .startNow() .withSchedule(simpleSchedule() .withIntervalInMinutes(5) .repeatForever()) .build(); 
0
source

Instead

 0 0/5 * * * ? 

using

 0 */5 * * * * 

Edit:. This leads to the fact that your task is executed in 0 seconds of every minute, which is divided by 5.

Change 2: 0/5 means only minutes 0 and 5.

+4
source

Do not use the cron schedule, but a simple schedule:

 Trigger trigger = newTrigger(). withIdentity("Id1Trigger", "Rome"). withSchedule( simpleSchedule(). withIntervalInMinutes(5). repeatForever() ).build(); 
+4
source

Source: https://habr.com/ru/post/1394173/


All Articles