public class ManuallyTriggeredScheduledExecutorService extends Object implements ScheduledExecutorService
ScheduledExecutorService implementation for testing purposes. It spawns no
threads, but lets you trigger the execution of tasks manually.
This class is helpful when implementing tests tasks synchronous and control when they run, which would otherwise asynchronous and require complex triggers and latches to test.
| 构造器和说明 |
|---|
ManuallyTriggeredScheduledExecutorService() |
public ManuallyTriggeredScheduledExecutorService()
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
schedule 在接口中 ScheduledExecutorServicepublic <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
schedule 在接口中 ScheduledExecutorServicepublic ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
scheduleAtFixedRate 在接口中 ScheduledExecutorServicepublic ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
public void shutdown()
shutdown 在接口中 ExecutorServicepublic List<Runnable> shutdownNow()
shutdownNow 在接口中 ExecutorServicepublic boolean isShutdown()
isShutdown 在接口中 ExecutorServicepublic boolean isTerminated()
isTerminated 在接口中 ExecutorServicepublic boolean awaitTermination(long timeout,
TimeUnit unit)
throws InterruptedException
awaitTermination 在接口中 ExecutorServiceInterruptedExceptionpublic <T> Future<T> submit(Callable<T> task)
submit 在接口中 ExecutorServicepublic <T> Future<T> submit(Runnable task, T result)
submit 在接口中 ExecutorServicepublic Future<?> submit(Runnable task)
submit 在接口中 ExecutorServicepublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
invokeAll 在接口中 ExecutorServicepublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
invokeAll 在接口中 ExecutorServicepublic <T> T invokeAny(Collection<? extends Callable<T>> tasks)
invokeAny 在接口中 ExecutorServicepublic <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
invokeAny 在接口中 ExecutorServicepublic void triggerAllNonPeriodicTasks()
triggerAll() and triggerNonPeriodicScheduledTasks() that allows making a test agnostic of how exactly a
runnable is passed to the executor.public void triggerAll()
queuedRunnables.public void trigger()
public int numQueuedRunnables()
public Collection<ScheduledFuture<?>> getActiveScheduledTasks()
public Collection<ScheduledFuture<?>> getActivePeriodicScheduledTask()
public Collection<ScheduledFuture<?>> getActiveNonPeriodicScheduledTask()
public List<ScheduledFuture<?>> getAllScheduledTasks()
public List<ScheduledFuture<?>> getAllPeriodicScheduledTask()
public List<ScheduledFuture<?>> getAllNonPeriodicScheduledTask()
public void triggerScheduledTasks()
public void triggerNonPeriodicScheduledTask()
NoSuchElementException - If there is no such task.public void triggerNonPeriodicScheduledTasksWithRecursion()
triggerNonPeriodicScheduledTasks(), if such a task schedules another non-periodically
schedule task, then this new task will also be triggered.public void triggerNonPeriodicScheduledTasks()
public void triggerPeriodicScheduledTasks()
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.