我遇到了一个特定的小时工问题,该问题无法使用Quartz Scheduler触发。
当前,除每小时的工作外,其他所有工作都可以被解雇。仅当我将程序打包成.jar文件并使用屏幕在Ubuntu服务器上运行它时,才会发生此错误,但是在本地IDE上运行时,触发器将正确触发。
感谢帮助调试此问题。谢谢!
Main.Java
public static void main(String[] args) throws Exception {
System.out.println("Aggregator Service Started");
JobDetail hourlyJob = JobBuilder.newJob(HourlyJob.class)
.withIdentity("HourlyJob", "group1").build();
JobDetail DailyJob = JobBuilder.newJob(Jobs.DailyJob.class)
.withIdentity("DailyJob", "group1").build();
JobDetail WeeklyJob = JobBuilder.newJob(Jobs.WeeklyJob.class)
.withIdentity("WeeklyJob", "group1").build();
JobDetail MonthlyJob = JobBuilder.newJob(Jobs.MonthtyJob.class)
.withIdentity("Monthly", "group1").build();
//Debugging trigger. Triggers the job instantly
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("DailyJob", "group1")
.startNow()
.build();
Trigger hourlyTrigger = newTrigger()
.withIdentity("HourlyTrigger", "group1")
.withSchedule(cronSchedule("0 0 * ? * * *"))
.build();
Trigger dailyTrigger = newTrigger()
.withIdentity("DailyTrigger", "group2")
.withSchedule(cronSchedule("0 8 0 1/1 * ? *"))
.build();
Trigger monthlyTrigger = newTrigger()
.withIdentity("MonthlyTrigger", "group4")
.withSchedule(cronSchedule("0 0 1 1 1/1 ? *"))
.build();
// schedule it
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(hourlyJob, hourlyTrigger);
scheduler.scheduleJob(DailyJob, dailyTrigger);
scheduler.scheduleJob(MonthlyJob, monthlyTrigger);
HourlyJob.java
public void execute(JobExecutionContext context)
throws JobExecutionException {
DateTime startDate = new DateTime()
.withMinuteOfHour(0)
.toDateTime(DateTimeZone.UTC)
.withSecondOfMinute(0);
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
System.out.println("Hourly Job Started at " + startDate.plusHours(1));
openConnection();
// other work
}