eclipse-ee4j / glassfish-concurro

Eclipse Concurrō project
https://projects.eclipse.org/projects/ee4j.glassfish
Other
15 stars 19 forks source link

Use Javatime in Managed Scheduled Thread Pool Executor #82

Closed aubi closed 8 months ago

aubi commented 8 months ago

Previous implementation used number of milliseconds for scheduling. The problem was during scheduling every second, sometimes the process was too fast, under 1 millisecond. The last time lost the nanoseconds part, e.g. ZonedDateTime planned the next execution to the exact same time. Keeping nanoseconds forces planning to the next second.

Example of executions with schedule "* * * * * *":

  Cron Trigger running, #4 at 19:30:22.302340267
  Cron Trigger running, #5 at 19:30:23.000287937
  Cron Trigger running, #6 at 19:30:23.303162670
  Cron Trigger running, #7 at 19:30:24.000863731

The value 19:30:23.000287937 was converted to milliseconds, e.g. time 19:30:23 and the next schedule was 19:30:23 This is the behavior of CronTrigger, see its test: 2023, 4, 22, 12 -> 2023, 4, 22, 12.

This change uses ZonedDateTime instead of long, so it doesn't loose the nanoseconds and the next schedule after 19:30:23.000287937 is 19:30:24.