• 社区居民
  • 忠实会员
  • 原创写手

quartz not run the job at the exact time prescribe

更多 发布于:2016-05-16 10:53
Currently im working on my project which will use quartz scheduler 2.2.1, I want to run the job with quartz everyday at 3:21:00 PM and the code below work find. the only problem is the quartz not execute my time exactly as i instruct, for the first time it run exactly at specific time but on the next day and so on it will run only 10 second,30second or more after the time it suppose to execute. i need the quartz to run exactly at the time i have prescribe. does any one of you have the same problem, what is the way to solve this. public class QuartzDaily {
public static void main(String[] args) throws ParseException, SchedulerException{

//quart schedule to run job everyday

Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

Date startDate = new SimpleDateFormat("dd.M.yyyy hh:mm:ss a").parse("05.6.2014 3:21:00 PM");  

JobDetail job = newJob(TestJob.class)
.withIdentity("Job1", "groupJob1")

Trigger trigger = newTrigger()
  .withIdentity("trigger1", "grouprigger")
  .startAt(startDate)  // first fire time 15:21:00
        .withIntervalInHours(1*24) // interval is actually set at 24 hours' worth of milliseconds

scheduler.scheduleJob(job, trigger);
System.out.println("Cron has started");


//class containb job to run
public static class TestJob implements Job {
       public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("Job is Running");

The answer for My Question is: If you manually change your computer system clock to jump on the date you set the quartz to run, it will effect the quartz job performance. it will take longer to start executing the job.Probably the clock system was having temporary problem to sync all the process within with the newly adjusted time. I have try this my selves and i believe the best way to test your quartz schedule is to wait for the actual date or time to come. i have try experimenting my selves for three days start from Friday until Monday morning. i set the quartz to run every 5 minute, 20 minutes, 2 hours, 4 hours, daily and every 2 days. al the job run exactly at the time specify. hope this can be useful tip to other.










喜欢0 评分0