我已经为Java项目实现了Quartz调度程序。我还配置了JDBCJobStore来存储MySQL数据库中的所有作业,以便它可以在重启后恢复作业。我现在遇到的问题是,调度程序在启动应用程序时不会恢复任何作业。当我注释掉JDBCJobStore配置时,调度程序按预期工作,但它只适用于JDBCJobStore配置。我在下面添加了类和配置文件。我错过了什么吗?任何帮助都将受到高度赞赏。
quartz.properties
org.quartz.scheduler.instanceName=Scheduler Instance
org.quartz.scheduler.instanceId=AUTO
org.quartz.scheduler.rmi.export=false
org.quartz.scheduler.rmi.proxy=false
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=5
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.dataSource=myDS
org.quartz.jobListener.listener.class=com.jobs.SchedulerJobListener
org.quartz.dataSource.myDS.driver=com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL=jdbc:mysql://[host]:[port]/[db]?useSSL=false
org.quartz.dataSource.myDS.user=[user]
org.quartz.dataSource.myDS.password=[pass]
org.quartz.dataSource.myDS.maxConnections=30
org.quartz.dataSource.myDS.validationQuery=SELECT 1
FutureEventScheduler.java
public class FutureEventScheduler {
private Scheduler scheduler = null;
private JobDetail job;
private Trigger trigger;
private Logger logger = Logger.getLogger(FutureEventScheduler.class);
private void initialize() {
try {
scheduler = new StdSchedulerFactory().getScheduler();
job = JobBuilder.newJob(FutureEventSchedulerJob.class).withIdentity("Future Event Job", Config.getSdkName()).requestRecovery(true).storeDurably(true).build();
trigger = TriggerBuilder.newTrigger().withIdentity("Future Event Trigger", Config.getSdkName()).withSchedule(
CronScheduleBuilder.cronSchedule("*/3 * * * * ?")
).build();
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
}
}
public FutureEventScheduler() {
initialize();
}
public void start() throws SchedulerException {
scheduler.start();
try {
scheduler.scheduleJob(job, trigger);
} catch (ObjectAlreadyExistsException e) {
logger.info("Already exists in database. Will restore it. " + e.getMessage());
}
}
public void stop() throws SchedulerException {
scheduler.shutdown();
}
FutureEventSchedulerJob.java
public class FutureEventSchedulerJob implements Job {
private static Logger logger = Logger.getLogger(FutureEventSchedulerJob.class);
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
logger.debug("future job");
}
}