私はこの方法でジョブをスケジュールしたい: 1)スレッドを1つだけ実行する。 (シリアル) 2)2つのラン間の一定間隔でSpring @Scheduled fixedDelayが期待どおりに動作しない
@Scheduled(fixedDelay = 10000)
私のメソッドの上には<task:annotation-driven/>
私のapplicationContext.xmlに使用します。しかし、私の印刷情報によれば、2つのジョブの間隔は、設定した10000msではありません。何故ですか?
19:07-25 22:38:46.190 INFO schedule:33 [21-thread-1] - [job#1] is running. -----> 1469457526190
20:07-25 22:38:48.191 INFO schedule:45 [21-thread-1] - [job#1] use 2000ms
21:07-25 22:38:48.191 INFO schedule:47 [21-thread-1] - [job#1] is finished. -----> 1469457528191
25:07-25 22:39:03.198 INFO schedule:33 [21-thread-1] - [job#1] is running. -----> 1469457543198
26:07-25 22:39:05.201 INFO schedule:45 [21-thread-1] - [job#1] use 2002ms
27:07-25 22:39:05.202 INFO schedule:47 [21-thread-1] - [job#1] is finished. -----> 1469457545202
31:07-25 22:39:20.205 INFO schedule:33 [21-thread-1] - [job#1] is running. -----> 1469457560205
32:07-25 22:39:22.209 INFO schedule:45 [21-thread-1] - [job#1] use 2004ms
33:07-25 22:39:22.210 INFO schedule:47 [21-thread-1] - [job#1] is finished. -----> 1469457562210
37:07-25 22:39:37.213 INFO schedule:33 [21-thread-1] - [job#1] is running. -----> 1469457577213
38:07-25 22:39:39.215 INFO schedule:45 [21-thread-1] - [job#1] use 2002ms
39:07-25 22:39:39.215 INFO schedule:47 [21-thread-1] - [job#1] is finished. -----> 1469457579215
43:07-25 22:39:54.221 INFO schedule:33 [21-thread-1] - [job#1] is running. -----> 1469457594221
44:07-25 22:39:56.225 INFO schedule:45 [21-thread-1] - [job#1] use 2004ms
45:07-25 22:39:56.225 INFO schedule:47 [21-thread-1] - [job#1] is finished. -----> 1469457596225
49:07-25 22:40:11.525 INFO schedule:33 [21-thread-1] - [job#1] is running. -----> 1469457611525
50:07-25 22:40:13.528 INFO schedule:45 [21-thread-1] - [job#1] use 2003ms
51:07-25 22:40:13.529 INFO schedule:47 [21-thread-1] - [job#1] is finished. -----> 1469457613529
55:07-25 22:40:28.237 INFO schedule:33 [21-thread-1] - [job#1] is running. -----> 1469457628237
終了してから実行するまでの時間が10000msでないことがわかります。
(以上15000のような)コードは(春4.2.1)である:
@Scheduled(fixedDelay = 10000)
public void timerJob1(){
SCHEDULER.info("[job#1] is running. -----> {}", System.currentTimeMillis());
Stopwatch stopwatch = Stopwatch.createStarted();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
long use = stopwatch.elapsed(TimeUnit.MILLISECONDS);
SCHEDULER.info("[timeJob1] use {}ms", use);
}
long use = stopwatch.elapsed(TimeUnit.MILLISECONDS);
SCHEDULER.info("[job#1] use {}ms", use);
SCHEDULER.info("[job#1] is finished. -----> {}", System.currentTimeMillis());
}