Quartz调度程序作业未存储在数据库中

时间:2011-12-19 14:23:42

标签: java jdbc quartz-scheduler

当我使用QuartzHelper.getScheduler().checkExists(new JobKey(name,group_name));来管理调度程序中的作业时 - quartz会在DB中查找它(看到它我只是删除了表并在该metod上获得了jdbc异常)。

然后将新作业添加到调度程序中,不会向DB添加任何记录。当我尝试创建一个具有相同名称的新作业时,作业正在运行 - 异常被触发。例外:

Unable to store Job : 'jobname', because one already exists with this identification.
at org.quartz.simpl.RAMJobStore.storeJob(RAMJobStore.java:277)

显然,使用RAMJobStore而不是JDBC。

问题:我做错了什么以及如何在DB中制作石英存储数据?

我有下一个石英配置:

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = myDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = false
org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://127.0.0.1:3306/quartz
org.quartz.dataSource.myDS.user = root
org.quartz.dataSource.myDS.password = qwerty
org.quartz.dataSource.myDS.maxConnections = 10

以下是代码:

JobBuilder builder = JobBuilder.newJob(ScriptBaseJob.class);
builder.withIdentity(name, GROUP_NAME);
JobDataMap dataMap = new JobDataMap(params);
builder.usingJobData(dataMap);
builder.requestRecovery(true);
builder.storeDurably(true);
JobDetail jobDetail = builder.build();

SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
scheduleBuilder.repeatForever();
scheduleBuilder.withIntervalInSeconds(60);

Trigger trigger = null;
try {
    trigger = QuartzHelper.getScheduler().getTrigger(new TriggerKey(name, GROUP_NAME));
} catch (Exception e) {
    e.printStackTrace();
}
if (trigger==null) {
    TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
    triggerBuilder.withSchedule(scheduleBuilder);
    triggerBuilder.withIdentity(name, GROUP_NAME);
    trigger = triggerBuilder.build();
}

SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
sched.start();

sched.scheduleJob(jobDetail, trigger);

1 个答案:

答案 0 :(得分:1)

应用程序似乎使用默认设置。该对象从

返回的形式是什么
  

QuartzHelper.getScheduler()