2015-09-28 58 views
1

我使用石英2.2.1和MySQL的作業存儲,爲新的作業創建,它覆蓋與舊作業數據的MySQL表中的表內容。 沒有錯誤。石英Schduler作業數據覆蓋Jobstore表

這是我的代碼:

import org.quartz.Scheduler; 
import org.quartz.SchedulerException; 
import org.quartz.Trigger; 
import org.quartz.TriggerBuilder; 
import org.quartz.impl.StdSchedulerFactory; 
import org.quartz.JobDetail; 

import static org.quartz.JobBuilder.newJob; 
import static org.quartz.SimpleScheduleBuilder.simpleSchedule; 

public class OwnScheduler { 

    public static void main(String[] args) throws InterruptedException, SchedulerException{ 

     Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); 
     try { 
      // Grab the Scheduler instance from the Factory 

      // and start it off 
      scheduler.start(); 

      JobDetail job1 = newJob(FetchJob.class).storeDurably(true).withIdentity("test4","Group4").build(); 
      Trigger trigger = (Trigger) TriggerBuilder.newTrigger() 
        .withIdentity("Trigger2", "Group4").startNow() 
        .withSchedule(simpleSchedule() 
         .withIntervalInSeconds(2)) 
         .build(); 
      Thread.sleep(90L * 10L); 

      scheduler.scheduleJob(job1, (Trigger) trigger); 

      scheduler.shutdown(); 

     } catch (Exception se) { 
      se.printStackTrace(); 
     } 
    } 
} 

和我的屬性文件:

org.quartz.scheduler.instanceName = MyScheduler 
org.quartz.scheduler.instanceId = NON_CLUSTERED 
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool 
org.quartz.threadPool.threadCount = 50 
org.quartz.scheduler.jobFactory.class = org.quartz.simpl.SimpleJobFactory 
org.quartz.jobStore.useProperties = true 
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT 
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate 
org.quartz.jobStore.tablePrefix = QRTZ_ 
org.quartz.jobStore.dataSource = quartz 
org.quartz.jobStore.nonManagedTXDataSource = quartz 
org.quartz.dataSource.quartz.driver = com.mysql.jdbc.Driver 
org.quartz.dataSource.quartz.URL = jdbc:mysql://localhost/quartz 
org.quartz.dataSource.quartz.user = root 
org.quartz.dataSource.quartz.password = password 

我在做什麼錯。

爲每個作業創建表格數據被新的作業細節覆蓋。 感謝您的關注。

回答

0

你是怎麼調用這段代碼的?您在初始化Quartz,Job和Trigger的JVM運行時有一個主要條目,您可以調度該作業,然後關閉調度程序。你爲什麼不僅僅根據某些條件開始計劃和退出?