2011-12-19 79 views
2

當我使用QuartzHelper.getScheduler().checkExists(new JobKey(name,group_name));在調度作業後看 - 石英查找它在DB(看到它,我只是刪除表,並獲得對梅託德的JDBC除外)。Quartz調度作業未存儲在數據庫中

但隨後的新作業添加到調度沒有記錄被添加到數據庫中。如果我嘗試製作一個具有相同名稱的新作業,那麼作業正在運行 - 異常被解僱。例外:

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

很明顯,使用RAMJobStore代替JDBC。

問題:我做錯了什麼,我能做些什麼來使石英儲存數據在數據庫?

我下石英配置:

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

看來,應用程序使用默認設置。什麼對象從

返回形式

QuartzHelper.getScheduler()

+1

謝謝,僅此而已。我必須從輔助類調度實例,並從石英例子SchedulerFactory是不必要的。 – Minolan 2011-12-20 09:23:43

相關問題