-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Scheduler
A scheduler that submits a task to an executor after a given delay.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static SchedulerdisabledScheduler()Returns a scheduler that always returns a successfully completed future.static SchedulerforScheduledExecutorService(ScheduledExecutorService scheduledExecutorService)Returns a scheduler that delegates to the aScheduledExecutorService.static SchedulerguardedScheduler(Scheduler scheduler)Returns a scheduler that suppresses and logs any exception thrown by the delegatescheduler.Future<?>schedule(Executor executor, Runnable command, long delay, TimeUnit unit)Returns a future that will submit the task to the given executor after the given delay.static SchedulersystemScheduler()Returns a scheduler that uses the system-wide scheduling thread by usingCompletableFuture.delayedExecutor(long, java.util.concurrent.TimeUnit, java.util.concurrent.Executor).
-
-
-
Method Detail
-
schedule
Future<?> schedule(Executor executor, Runnable command, long delay, TimeUnit unit)
Returns a future that will submit the task to the given executor after the given delay.- Parameters:
executor- the executor to run the taskcommand- the runnable task to scheduledelay- how long to delay, in units ofunitunit- aTimeUnitdetermining how to interpret thedelayparameter- Returns:
- a scheduled future representing pending submission of the task
-
disabledScheduler
static Scheduler disabledScheduler()
Returns a scheduler that always returns a successfully completed future.- Returns:
- a scheduler that always returns a successfully completed future
-
systemScheduler
static Scheduler systemScheduler()
Returns a scheduler that uses the system-wide scheduling thread by usingCompletableFuture.delayedExecutor(long, java.util.concurrent.TimeUnit, java.util.concurrent.Executor).- Returns:
- a scheduler that uses the system-wide scheduling thread
-
forScheduledExecutorService
static Scheduler forScheduledExecutorService(ScheduledExecutorService scheduledExecutorService)
Returns a scheduler that delegates to the aScheduledExecutorService.- Parameters:
scheduledExecutorService- the executor to schedule on- Returns:
- a scheduler that delegates to the a
ScheduledExecutorService
-
guardedScheduler
static Scheduler guardedScheduler(Scheduler scheduler)
Returns a scheduler that suppresses and logs any exception thrown by the delegatescheduler.- Parameters:
scheduler- the scheduler to delegate to- Returns:
- a scheduler that suppresses and logs any exception thrown by the delegate
-
-