1

In Spring I use standard CRON job scheduling to do some business level measurements every 10 minutes with this example

@Async
@Scheduled(cron = "0 0/10 * * * ?")
public void takeMeasurements() {
    Instant dateTimeNow = Instant.now();

    // Business impl of measurements taking & storing into DB
}

I've had no problem with this impl in under multiple customer environments (Win, MacOS, Linux) running as SpringBoot containers in docker but I observed that in one Win10 Enterprise environment the timestamp coming from Instant.now() called when CRON job fires has time "in past" e.g. 11:59:59:998 with job that was supposed to be fired at 12:00:00.

I can handle this scenario with some accepted range of deviation (for my purposes it's OK to do "rounding" of +-30s) but for some folks/scenarios it might not be.

Where is the underlying problem of this?

Doesn't CRON use same machine clock as java.time.Instant uses?

Lukas
  • 31
  • 3
  • Have you tried to run a code on Java 9+? It is also a good solution was described by @StormeHawke - https://stackoverflow.com/a/20689298/12312179 – mvn.2047 Nov 20 '22 at 18:58
  • Forgot to mention - all my containers run with JDK 11 – Lukas Nov 20 '22 at 19:40

0 Answers0