2013-02-13 7 views
7

これはかなり簡単ですが、実行されているジョブはありません。私はタスクのexecute()メソッドにブレークポイントを持っています。 何が間違っているのか分かりません。クォーツが単純なトリガを発射しない

仕事

class Printer implements Job{ 
    public Printer(){ 
     System.out.println("created printer"); 
    } 

    @Override 
    public void execute(JobExecutionContext context) 
      throws JobExecutionException { 
     System.out.println("hi" + context.getFireTime()); 
    } 

} 

class MyClass { 
     public static void main(String[] args) throws Throwable { 
      Scheduler s = StdSchedulerFactory.getDefaultScheduler(); 
      JobDetail job = newJob(Printer.class).build(); 
      CronTrigger trigger = 
        newTrigger() 
        .withIdentity("a", "t") 
        .withSchedule(cronSchedule("0/5 * * * * ?").inTimeZone(TimeZone.getDefault())) 
        .forJob(job).build(); 
      s.scheduleJob(job, trigger); 

// This prints the right date! 

      System.out.println(trigger.getNextFireTime()); 
      s.start(); 
     } 
} 

EDITは、メインクラス:私はquartz.propertyファイルを持っていなかった発見し、その石英のためのスレッドプールだった可能性がありました決して作成されていません。したがってdocumentationに読んで、私は次のようにStdSchedulerFactoryを使用してコードを置き換える:

DirectSchedulerFactory.getInstance().createVolatileScheduler(10); 
Scheduler s = DirectSchedulerFactory.getInstance().getScheduler(); 

は何を思いますか?まだ運はありません。同じ効果。アプリケーションは起動し続け、発射はトリガーしません。

+1

あなたのプログラムは終了しませんか? – Dariusz

+0

いいえ、私はスケジューラをシャットダウンしないためです(意図的に)。 – sscarduzio

+0

あなたのアプリケーションが単に 's.start()'の直後に終了するのではないことを実際に確認しましたか? – Dariusz

答えて

9

解決策を見つけました。ジョブ(プリンタ)を定義するクラスの可視性を公開に変更すると、Quartzがそのオブジェクトにアクセスして実行できるようになります。それは、スケジューラへ<? extends Job>.class 渡すことのみ可能なので、理解しやすいです

public class Printer implements Job{ // just add 'public'! 
    public Printer(){ 
     System.out.println("created printer"); 
    } 

    @Override 
    public void execute(JobExecutionContext context) 
      throws JobExecutionException { 
     System.out.println("hi" + context.getFireTime()); 
    } 

} 

(血まみれの地獄を、なぜ??)とない - 匿名オブジェクト - 例えば。

これがあると、私は、Quartzが単一のエラーメッセージを表示せずにサイレントジョブをサイレントに失敗させる方法を実際に惑わせることがわかりました。

+3

constractorがパラメータを必要とするか、publicでない場合、別の問題が発生する可能性があります。私はあなたのおかげで問題を見つけました。 –

+2

私は同じ問題がありました。私はまた、非常に奇妙な/エラーメッセージは全く与えられていないことがわかります... –