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();
    }

}  
4

1 回答 1

1

由于您使用 Spring 标记了您的问题,因此我假设您正在使用它。您应该在此处查看Spring 3 中关于调度所做的更改。

另一方面,当然可以使用纯石英来实现,可能我会为CronTrigger使用 cron 表达式,如下所示:

0/2 * * * * *
于 2012-12-03T08:25:26.477 回答