CronScheduler

Alternative to ScheduledThreadPoolExecutor proof against the clock drift problem

Лицензия

Лицензия

Группа

Группа

io.timeandspace
Идентификатор

Идентификатор

cron-scheduler
Последняя версия

Последняя версия

0.1
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

CronScheduler
Alternative to ScheduledThreadPoolExecutor proof against the clock drift problem
Ссылка на сайт

Ссылка на сайт

https://github.com/TimeAndSpaceIO/CronScheduler
Система контроля версий

Система контроля версий

https://github.com/TimeAndSpaceIO/CronScheduler

Скачать cron-scheduler

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

CronScheduler: a reliable Java scheduler for external interactions

Maven Central Build Status

CronScheduler is an alternative to ScheduledThreadPoolExecutor and Timer with the following advantages:

  • CronScheduler is proof against unbounded clock drift relative to UTC or system time for both one-shot or periodic tasks.
  • It takes into account machine suspension (like sleep or hibernation).
  • 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.

Usage

Maven:

<dependency>
  <groupId>io.timeandspace</groupId>
  <artifactId>cron-scheduler</artifactId>
  <version>0.1</version>
</dependency>

Gradle:

dependencies {
  compile 'io.timeandspace:cron-scheduler:0.1'
}

Server-side usage example:

Duration syncPeriod = Duration.ofMinutes(1);
CronScheduler cron = CronScheduler.create(syncPeriod);
cron.scheduleAtFixedRateSkippingToLatest(0, 1, TimeUnit.MINUTES, runTimeMillis -> {
    // Collect and send summary metrics to a remote monitoring system
});

Client-side usage example:

Duration oneHour = Duration.ofHours(1);
CronScheduler cron = 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().

See Javadocs.

io.timeandspace

Версии библиотеки

Версия
0.1