Please consider the following code
String pattern = "*/17 * * * *";
Date d = new Date();
for (int i = 0; i < 10; i++) {
System.out.println("Start: " + d + ", " + (d = new Predictor(pattern, d).nextMatchingDate()));
}
This outputs the following sample (I put the times I didn't expect between brackets):
Start: Tue Jun 11 12:54:48 GMT+02:00 2013, Tue Jun 11 (13:00:00) GMT+02:00 2013
Start: Tue Jun 11 13:00:00 GMT+02:00 2013, Tue Jun 11 13:17:00 GMT+02:00 2013
Start: Tue Jun 11 13:17:00 GMT+02:00 2013, Tue Jun 11 13:34:00 GMT+02:00 2013
Start: Tue Jun 11 13:34:00 GMT+02:00 2013, Tue Jun 11 13:51:00 GMT+02:00 2013
Start: Tue Jun 11 13:51:00 GMT+02:00 2013, Tue Jun 11 (14:00:00) GMT+02:00 2013
Start: Tue Jun 11 14:00:00 GMT+02:00 2013, Tue Jun 11 14:17:00 GMT+02:00 2013
Start: Tue Jun 11 14:17:00 GMT+02:00 2013, Tue Jun 11 14:34:00 GMT+02:00 2013
Start: Tue Jun 11 14:34:00 GMT+02:00 2013, Tue Jun 11 14:51:00 GMT+02:00 2013
Start: Tue Jun 11 14:51:00 GMT+02:00 2013, Tue Jun 11 (15:00:00) GMT+02:00 2013
Start: Tue Jun 11 15:00:00 GMT+02:00 2013, Tue Jun 11 15:17:00 GMT+02:00 2013
Although the pattern is configured to match minutes divisible by 17, if that's a correct way to describe it, the predictor considers a precise hour (13:00, 14:00, 15:00..etc) a valid next-matching-date !
My questions are:
- Is this behavior valid ? If yes, then why is it valid ?
- How can I prevent this behavior ? I mean how can I prevent the predictor from considering a precise hour as a matching time if the time field (i.e. minutes, hours, days, week day) isn't divisible by it's maximum value (i.e. 60, 24, 30 or 31, 7) ?
- Is this actually the case with unix cron scheduling ?
Thank you.