- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A scheduler that submits a task to an executor after a given delay.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SchedulerReturns 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.Returns a future that will submit the task to the executor after the given delay.static SchedulerReturns a scheduler that uses the system-wide scheduling thread by usingCompletableFuture.delayedExecutor(long, java.util.concurrent.TimeUnit, java.util.concurrent.Executor).
-
Method Details
-
schedule
Future<? extends @Nullable Object> schedule(Executor executor, Runnable command, long delay, TimeUnit unit) Returns a future that will submit the task to the 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 the pending submission of the task
-
disabledScheduler
Returns a scheduler that always returns a successfully completed future.- Returns:
- a scheduler that always returns a successfully completed future
-
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
Returns a scheduler that delegates to the aScheduledExecutorService.Note that this implementation will ignore scheduling the task if the executor was shutdown or the submission was rejected. Consider implementing your own adapter if different behavior is required.
- Parameters:
scheduledExecutorService- the executor to schedule on- Returns:
- a scheduler that delegates to the a
ScheduledExecutorService
-
guardedScheduler
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
-