簡體   English   中英

Quartz Scheduler無法啟動cron作業

[英]Quartz scheduler is failing to start the cron job

嗨,我正在使用Quartz調度程序來觸發需要執行大量活動的cron。 我的代碼如下:

在我的InitServlet類的init()方法中,我正在定義我的TimerServer

    public class InitServlet extends HttpServlet {
      public void init(ServletConfig config) throws ServletException {
         try {
            System.out.println("Starting the CRON");
            //Set the DSO Handler CRON
            TimerServer task = TimerServer.getInstance();
            task.setTask();
        }  catch (Exception ex) {
            System.out.println("Failed to start the cron");
            ex.printStackTrace();
        }
    }

在我的TimerServer類中,我具有以下方法

    public void setTask() {
        try{            
            this.setSubscriptionDailyJob();
        } catch(SchedulerException ex) {
            log.error("SchedulerException: "+ex.getMessage(), ex);
        }

private void setSubscriptionDailyJob() throws SchedulerException {
       log.info("Step 1 ");

       Scheduler scheduler = schedulerFactory.getScheduler();
       log.info("Step 2 ");

        JobDetail subscriptionJob = new JobDetail("subscription", "subscriptiongroup",           SubscriptionDaily.class);
 log.info("Step 3 ");
        // Initiate CronTrigger with its name and group name
        CronTrigger subscriptionCronTrigger = new CronTrigger("subscriptionCronTrigger", "subscriptionTriggerGroup");

        try {
            log.info("Subscription cron: "+Constants.SUBSCRIPTION_CRON);
            // setup CronExpression
            CronExpression cexp = new CronExpression(Constants.SUBSCRIPTION_CRON);
            // Assign the CronExpression to CronTrigger
           subscriptionCronTrigger.setCronExpression(cexp);
        } catch (Exception ex) {
            log.warn("Exception: "+ex.getMessage(), ex);
        }
        scheduler.scheduleJob(subscriptionJob, subscriptionCronTrigger);    
        scheduler.start();
    }

在我的SubscriptionDaily類別中:

public class SubscriptionDaily implements Job {    
    public void execute(JobExecutionContext arg0) throws JobExecutionException {
      //Actions to be performed
    }
}

現在檢查我的日志,我正在執行步驟1,步驟2,但沒有進一步。

我的代碼被卡在TimerServer類本身上。 到調度程序的日志是:

17:24:43 INFO  [TimerServer]: Step 1       
17:24:43 INFO  [SimpleThreadPool]: Job execution threads will use class loader of thread: http-8080-1     
17:24:43 INFO  [SchedulerSignalerImpl]: Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl                                              
17:24:43 INFO  [QuartzScheduler]: Quartz Scheduler v.1.6.5 created.   
17:24:43 INFO  [RAMJobStore]: RAMJobStore initialized.                             
17:24:43 INFO  [StdSchedulerFactory]: Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'  
17:24:43 INFO  [StdSchedulerFactory]: Quartz scheduler version: 1.6.5               17:24:43 INFO  [TimerServer]: Step 2

我認為缺少日志條目:[QuartzScheduler]:已啟動調度程序DefaultQuartzScheduler _ $ _ NON_CLUSTERED。

請幫忙。

我沒有在我的庫中包含common-collections jar,盡管沒有因為它而在我的應用程序中的任何地方拋出任何錯誤或異常。 所以我很茫然!

在此之前,我從未見過Java如此愚蠢。 這是Java的正確行為,還是我對此抱有太大期望?

我也在應用程序中使用spring,Spring提供了一種通過bean處理Quartz和Java的TimerTask功能的好簡單方法。 很少有優秀而精練的教程: http : //static.springsource.org/spring/docs/1.2.9/reference/scheduling.html http://www.javaranch.com/journal/200711/combining_spring_and_quartz.html

盡管使用bean方法的限制是,但是您必須在spring xml文件中對cron值進行硬編碼,因此我們將失去靈活性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM