You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It has convenient methods to prevent several tasks from piling up in case of blocks, long GC
pauses, or abrupt forward system time shifts (likely made by the user or the administrator of the
machine).
It correctly handles significant system time setbacks (backward shifts), likely made by the user
or the administrator of the machine.
It has convenient methods to schedule tasks at round times within a day in a given time zone
(for example, every midnight), transparently handling all time zone and daylight saving time complexity.
See this blog post
for more details and specific recommendations about when to use ScheduledThreadPoolExecutor,
CronScheduler, or other scheduling facilities.
DurationsyncPeriod = Duration.ofMinutes(1);
CronSchedulercron = CronScheduler.create(syncPeriod);
cron.scheduleAtFixedRateSkippingToLatest(0, 1, TimeUnit.MINUTES, runTimeMillis -> {
// Collect and send summary metrics to a remote monitoring system
});
Client-side usage example:
DurationoneHour = Duration.ofHours(1);
CronSchedulercron = CronScheduler.create(oneHour);
cron.scheduleAtRoundTimesInDaySkippingToLatest(oneHour, ZoneId.systemDefault(), runTimeMillis -> {
notifyUser("It's time to get up and make a short break from work!");
});
For drop-in replacement of ScheduledThreadPoolExecutor and integration with existing code, there
is an adapter: cronScheduler.asScheduledExecutorService().