@FunctionalInterface public interface Scheduler
| Modifier and Type | Method and Description |
|---|---|
static @NonNull Scheduler |
disabledScheduler()
Returns a scheduler that always returns a successfully completed future.
|
static @NonNull Scheduler |
forScheduledExecutorService(@NonNull ScheduledExecutorService scheduledExecutorService)
Returns a scheduler that delegates to the a
ScheduledExecutorService. |
static @NonNull Scheduler |
guardedScheduler(@NonNull Scheduler scheduler)
Returns a scheduler that suppresses and logs any exception thrown by the delegate
scheduler. |
@NonNull Future<?> |
schedule(@NonNull Executor executor,
@NonNull Runnable command,
@Positive long delay,
@NonNull TimeUnit unit)
Returns a future that will submit the task to the given executor after the given delay.
|
static @NonNull Scheduler |
systemScheduler()
Returns a scheduler that uses the system-wide scheduling thread if available, or else returns
disabledScheduler() if not present. |
@NonNull Future<?> schedule(@NonNull Executor executor, @NonNull Runnable command, @Positive long delay, @NonNull TimeUnit unit)
executor - the executor to run the taskcommand - the runnable task to scheduledelay - how long to delay, in units of unitunit - a TimeUnit determining how to interpret the delay parameterstatic @NonNull Scheduler disabledScheduler()
static @NonNull Scheduler systemScheduler()
disabledScheduler() if not present. This scheduler is provided in Java 9 or above
by using CompletableFuture delayedExecutor.static @NonNull Scheduler forScheduledExecutorService(@NonNull ScheduledExecutorService scheduledExecutorService)
ScheduledExecutorService.scheduledExecutorService - the executor to schedule onScheduledExecutorServicestatic @NonNull Scheduler guardedScheduler(@NonNull Scheduler scheduler)
scheduler.scheduler - the scheduler to delegate to