Environment: Java 7 on Amazon Linux AMI (patched). Note that NTP is used in this environment.
A portion of our code executes scheduled tasks periodically. Generally, the exact time of the execution is not particularly important. However, we have similar logic that is used to calculate intervals for reporting. The reporting periods are expected to fall on exact hour boundaries.
Sample code:
protected Calendar increment(ScheduledPeriodEnum scheduledPeriod, Calendar date) {
Calendar next = CalendarUtils.getCalendar();
next.setTimeInMillis(date.getTimeInMillis());
switch (scheduledPeriod) {
case ONE_DAY:
next.add(Calendar.DAY_OF_MONTH, 1);
break;
case ONE_HOUR:
next.add(Calendar.HOUR_OF_DAY, 1);
break;
case FIFTEEN_MINUTE:
next.add(Calendar.MINUTE, 15);
break;
case ONE_MONTH:
next.add(Calendar.MONTH, 1);
break;
default:
throw new RuntimeException("Unhandled case: " + scheduledPeriod);
}
return next;
}
We persist the time as a unix timestamp (long) value. The Calendar
instances all are in the UTC timezone.
It is our understanding that Java 7's Calendar implementation does not account for leap seconds. We also believe that NTP will update the OS clock.
We are aware of Amazon's 2012 leap second debacle. We are communicating directly with them to understand their operational preparations.
Specific questions:
If we are
increment
a Calendar that is on an hour boundary before the leap second, will it be on an hour boundary after the leap second? Or one second before the hour?How should we test/validate how this code will operate across the leap second boundary? Is a hacked NIST leapfile a good way to go?
Is there a more appropriate pattern/implementation that would sidestep the leap-second issue?