2012-12-03 48 views
0

我使用Quartz框架來安排工作。我想每2秒重複一次該操作。但它似乎只執行一次。我如何讓它永遠運行!石英運行一次

public static void main(String[] args) throws InterruptedException { 

    //ChangingRatesSimulator.doSimulation(); 
    try { 
     // Grab the Scheduler instance from the Factory 
     Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); 

     // and start it off 
     scheduler.start(); 
     JobDetail job = newJob(ChangingRatesSimulator.class).withIdentity("job1","group1").build(); 

     // compute a time that is on the next round minute 
     Date runTime = evenSecondDate(new Date()); 

     // Trigger the job to run on the next round minute 
     Trigger trigger = newTrigger() 
      .withIdentity("trigger1", "group1") 
      .startAt(runTime) 
      .withSchedule(simpleSchedule() 
        .withIntervalInSeconds(5) 
        .repeatForever()) 
      .build(); 
     scheduler.scheduleJob(job, trigger); 
     scheduler.start(); 





    } catch (SchedulerException se) { 
     se.printStackTrace(); 
    } 

} 
+0

你得到它的工作?我面臨着同樣的麻煩。請分享適合您的解決方案。 – Prashant

回答

1

既然您用Spring標記了您的問題,我假設您正在使用它。 您應該查看Spring 3中有關調度here的更改。

上當然也可以用純石英來實現的。另一方面,可能我會用cron表達式去爲CronTrigger,像這樣:

0/2 * * * * *