2013-10-11 25 views
3

我想要做的就是用一堆批處理文件(和參數)讀取一個文件,併爲每個條目創建一個石英作業。我知道我錯過了一些明顯的東西,但我似乎無法找到如何在谷歌的任何地方做到這一點。我發現的一切都表明,對於不能外部構建的每項工作,必須對新班級進行編碼。我似乎無法找到如何創建一個我可以傳入調度程序的類的實例。如何將作業對象實例傳遞給quartz調度程序

public class MyJob implements Job{ 
    private String[] jobArgs = null; 

    public MyJob(String[] jobArgs){ 
     this.jobArgs = jobArgs; 
    } 

    public void execute(JobExecutionContext arg0) throws JobExecutionException{ 
     ExternalProcess ep - new ExternalProcess(); 
     try{ 
      ep.runExecutableCommand(jobargs); 
     }catch(Exception e){...} 
    } 

} 

public class JobScheduler { 
    ... 
    List<String[]> jobArgList = loadJobListFromDisk(); 
    List<MyJob> = new ArrayList<MyJob>(); 
    for(String[] jobArgs : jobList){ 
     MyJob myJob = new MyJob(jobArgs); 
     // Is it possible to pass in a reference to an instance somehow 
     // instead of letting the scheduler create the instance based on 
     // the class definition? I know this syntax doesn't work, but this 
     // is the general idea of what I'm trying to do. 
     JobDetail jobDetail = JobBuilder.newJob(myJob).withIdentity... 
    } 
} 

回答

2

在quartz 2中,您需要使用JobDataMap(存儲在jobDetail中)將參數傳遞給execute方法。它可以在context.getJobDetail()中獲得。getJobDataMap()

0

從什麼時候用Quartz Scheduler或JobBuilder獲得高質量的時間,它以這種愚蠢的方式編寫,它只接受Class對象作爲參數。我無法找到將Job Object傳遞給構建器的方法。

這是一個非常糟糕的設計,至少會導致Quartz 1.000版通用解決方案出現問題。

相關問題