0

我可能只是个白痴-这是漫长的一天!我在第一次涉足 Quartz 时误解了一些东西......

鉴于此代码:

DateTime dt = new DateTime();
dt = dt.withDayOfMonth(20);

Calendar cal = new CronCalendar("0 0/10 * * * ?" );
long start = dt.getMillis();
System.out.println("Starting at " + start);
long end = start + 10;
long current = start;
int i = 0;
while (current < end) {
  if (i > 0) {
    System.out.println(i + ":" + current);
  }
  long next = cal.getNextIncludedTime(current);
  current = next;
  i++;
}

我希望输出中最多包含一个时间,因为时间窗口是 10 毫秒,而日历中包含的时间相隔 10 分钟。

但是当我运行它时:

Starting at 1250796103004
1:1250796103005
2:1250796103006
3:1250796103007
4:1250796103008
5:1250796103009
6:1250796103010
7:1250796103011
8:1250796103012
9:1250796103013

请帮忙!

4

1 回答 1

1

是的,我只是个笨蛋。

日历指定排除时间。

我应该一直使用 CronTrigger 来指定我想要包含的时间。代码应该看起来更像这样......

CronTrigger cal = new CronTrigger("Test", "Test", "0 0/10 * * * ?" );
...
end = start + 1000000;
...
while (current < end) {
  if (i > 0) {
  System.out.println(i + ":" + current);
  }
  Date next = cal.getFireTimeAfter(new Date(current));
  current = next.getTime();
  i++;
}

这给出了我期望的输出。

Starting at 1250798091337
1:1250798400000
2:1250799000000
于 2009-08-14T19:58:18.530 回答