Quartz调度程序作业未存储在数据库中
当我使用 QuartzHelper.getScheduler().checkExists(new JobKey(name,group_name)); 来管理调度程序中的作业时 -quartz 在数据库中查找它(要查看它,我只需删除表并在该方法上遇到 jdbc 异常)。
但随后新作业被添加到调度程序中,没有记录被添加到数据库中。当作业正在运行时,如果我尝试创建一个具有相同名称的新作业,则会引发异常。例外:
Unable to store Job : 'jobname', because one already exists with this identification.
at org.quartz.simpl.RAMJobStore.storeJob(RAMJobStore.java:277)
很明显使用RAMJobStore而不是JDBC。
问题:我做错了什么,我该怎么做才能使quartz将数据存储在数据库中?
我有下一个石英配置:
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);
When I use QuartzHelper.getScheduler().checkExists(new JobKey(name,group_name));
to look after a job in scheduler - quartz looks for it in DB (to see it I simply remove tables and got an jdbc exception on that metod).
But then the new job is added to scheduler no records is added to DB. While the job is running if I trying to make a new one with same name - exception is fired. The exception:
Unable to store Job : 'jobname', because one already exists with this identification.
at org.quartz.simpl.RAMJobStore.storeJob(RAMJobStore.java:277)
It is clearly that RAMJobStore is used instead of JDBC.
Question: what I am doing wrong and what can I do to make quartz store data in DB?
I've got next quartz config:
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
Here is the code:
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来应用程序使用默认设置。返回的对象来自什么
It appears that application uses default setting. What does the object returned form from