Domanda

Probabilmente sto solo di essere un idiota - è stata una lunga giornata! Ho frainteso qualcosa nella mia prima incursione nel quarzo ...

Dato questo codice:

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++;
}

Mi aspetto che ci sarà al massimo un tempo incluso nell'output, come la finestra di tempo è 10ms ei tempi inserita nel calendario sono 10 minuti a parte.

Ma quando l'eseguo:

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

Si prega di aiutare!

È stato utile?

Soluzione

Sì, solo a me di essere un idiota.

Calendari specificano tempi esclusi.

avrei usato un CronTrigger per specificare le volte che ho voluto inserire. Il codice dovrebbe essere più simile a questo ...

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++;
}

che fornisce l'output che mi aspettavo.

Starting at 1250798091337
1:1250798400000
2:1250799000000
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top