public class DeterministicScheduler extends Object implements ScheduledExecutorService
ScheduledExecutorService that executes commands on the thread that calls
runNextPendingCommand, runUntilIdle or
tick. Objects of this class can also be used
as Executors or ExecutorServices if you just want to control background execution
and don't need to schedule commands, but it may be simpler to use a DeterministicExecutor.| Constructor and Description |
|---|
DeterministicScheduler() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
TimeUnit unit) |
void |
execute(Runnable command) |
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks) |
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit) |
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks) |
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit) |
boolean |
isIdle()
Reports whether scheduler is "idle": has no commands pending immediate execution.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
runNextPendingCommand()
Runs the next command scheduled to be executed immediately.
|
void |
runUntilIdle()
Runs all commands scheduled to be executed immediately but does
not tick time forward.
|
<V> ScheduledFuture<V> |
schedule(Callable<V> callable,
long delay,
TimeUnit unit) |
ScheduledFuture<?> |
schedule(Runnable command,
long delay,
TimeUnit unit) |
ScheduledFuture<?> |
scheduleAtFixedRate(Runnable command,
long initialDelay,
long period,
TimeUnit unit) |
ScheduledFuture<?> |
scheduleWithFixedDelay(Runnable command,
long initialDelay,
long delay,
TimeUnit unit) |
void |
shutdown() |
List<Runnable> |
shutdownNow() |
<T> Future<T> |
submit(Callable<T> callable) |
Future<?> |
submit(Runnable command) |
<T> Future<T> |
submit(Runnable command,
T result) |
void |
tick(long duration,
TimeUnit timeUnit)
Runs time forwards by a given duration, executing any commands scheduled for
execution during that time period, and any background tasks spawned by the
scheduled tasks.
|
public void tick(long duration,
TimeUnit timeUnit)
duration - timeUnit - public void runUntilIdle()
public void runNextPendingCommand()
public boolean isIdle()
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
schedule in interface ScheduledExecutorServicepublic <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
schedule in interface ScheduledExecutorServicepublic ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
scheduleAtFixedRate in interface ScheduledExecutorServicepublic ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
scheduleWithFixedDelay in interface ScheduledExecutorServicepublic boolean awaitTermination(long timeout,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface ExecutorServiceInterruptedExceptionpublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
invokeAll in interface ExecutorServiceInterruptedExceptionpublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
invokeAll in interface ExecutorServiceInterruptedExceptionpublic <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
invokeAny in interface ExecutorServiceInterruptedExceptionExecutionExceptionpublic <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
invokeAny in interface ExecutorServiceInterruptedExceptionExecutionExceptionTimeoutExceptionpublic boolean isShutdown()
isShutdown in interface ExecutorServicepublic boolean isTerminated()
isTerminated in interface ExecutorServicepublic void shutdown()
shutdown in interface ExecutorServicepublic List<Runnable> shutdownNow()
shutdownNow in interface ExecutorServicepublic <T> Future<T> submit(Callable<T> callable)
submit in interface ExecutorServicepublic Future<?> submit(Runnable command)
submit in interface ExecutorServicepublic <T> Future<T> submit(Runnable command, T result)
submit in interface ExecutorServiceCopyright © 2003–2022 jMock. All rights reserved.