我必须安排每天在特定时间发送邮件,我希望有经验的意见。我想知道的是,这是否是使用 Quartz Scheduler 做这种事情的正确(最佳)方式:
# 代码
public static void startScheduler(){
SchedulerFactory sf = new StdSchedulerFactory();
try {
Scheduler sched = sf.getScheduler();
JobDetail job = newJob(SendDocumentsMailJob.class)
.withIdentity("sendMailJob", "group1")
.build();
Date startTime = todayAt(6,0,0);
SimpleTrigger trigger = newTrigger()
.withIdentity("everyDayAt6oClock", "group1")
.startAt(startTime)
.withSchedule(simpleSchedule()
.withIntervalInHours(24) // is this correct?
.repeatForever())
.build();
sched.scheduleJob(job,trigger);
sched.start();
System.out.println("Starting at: "+new Date());
System.out.println("Next trigger fires at: "+startTime);
// sched.shutdown(); // is this correct?
}catch (SchedulerException ex) { ex.printStackTrace();}
//catch (InterruptedException ex) { ex.printStackTrace();}
catch (Exception ex) { ex.printStackTrace();}
}
我没有找到任何设置每日间隔的方法,所以我使用了:withIntervalInHours(24),对吗?
调度程序将无限期运行,所以我不必调用shutdown(),对吗?
谢谢,