ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:924回复:0

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");  
System.out.println(startDate);

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

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

scheduler.scheduleJob(job, trigger);
scheduler.start();
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");
    }    
}
}
answer(解决方案):

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.

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部