5

Quartzプラグインを使用してGrailsWebアプリケーションでcronジョブを設定しようとしています。私は現在、次のコードを使用して、テストジョブを1秒に1回実行しようとしています。

class TestJob {
    private int counter = 0
    static triggers = {
        simple repeatInterval: 1000
    }

    def execute() {
        // execute job
        counter += 1
        System.out.println("Testing the cron " + counter)
    }
}

ただし、アプリケーションを実行すると、最初のexecute()呼び出しの初期出力が2回しか表示されません。1回はサーバーの実行が警告される直前、もう1回は直後です。

| Loading Grails 2.1.0
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 1 source files.....
| Running Grails application
Testing the cron 1
| Server running. Browse to http://localhost:8080/QuartzTest
Testing the cron 1

私のクォーツジョブが正しく起動しない理由を誰かが知っていますか?単純なものではなくcronを使用したり、さまざまなパラメーターや時間間隔などを使用したりしてみました。何も違いはありません。

ありがとう

4

4 に答える 4

12

同様の問題があったと思います。System.out.printlnクォーツジョブ内からの使用は許可されていません。を使用してみてくださいlog.error

于 2012-07-13T19:42:47.693 に答える
1

単純なトリガーにはrepeatCountフィールドがあります。無期限に実行するには、-1に設定します。

simple name: "testName", repeatInterval: 1000, repeatCount: -1
于 2012-07-13T19:54:42.077 に答える
0

ドキュメントでは、すべての例nameのトリガーブロックにパラメーターがあります。

static triggers = {
      simple name: "testName", repeatInterval: 1000      
}

ドキュメントには、指定されていない場合はデフォルト値が使用されると記載されていますが、最初にそのショットを示します。

于 2012-07-13T18:16:19.937 に答える
0

私は同じ問題を抱えていて、この結論に達しました:

クォーツジョブでSystem.out.printlnを使用できます。印刷行のあるメソッドをexecuteメソッドから分離する必要があります。1つのメソッドだけを呼び出すのはうまくいきませんでしたが、他の2つのメソッドを呼び出すと、印刷行で正しく繰り返されます。

class TestJob {
    static triggers = {
    simple name: 'testTrigger', startDelay: 1000, repeatInterval: 1000, repeatCount: -1
    }

    def execute() {
        exampleMethod()
        anotherMethod()
    }

    def exampleMethod(){
        System.out.println("test")
    }

    def anotherMethod(){
        System.out.println("another method")
   }
}

出力は次のとおりです。

| Loading Grails 2.1.1
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 2 source files.....
| Running Grails application

Configuring Spring Security UI ...
... finished configuring Spring Security UI


Configuring Spring Security Core ...
... finished configuring Spring Security Core

test
another method
| Server running. Browse to http://localhost:8080/
test
another method
test
another method
test
another method
test
another method
test
another method

これが誰かに役立つことを願っています!

于 2013-11-07T15:58:38.520 に答える