@Beta public class PausedExecutorService extends AbstractExecutorService
Executor service that queues any posted tasks.
Users must explicitly call runAll()
to execute all pending tasks.
Intended to be a replacement for RoboExecutorService
when using LooperMode.Mode#PAUSED
. Unlike RoboExecutorService
, will execute tasks on a background thread. This is useful to test Android code that enforces it runs off the main thread.
NOTE: Beta API, subject to change.
Constructor and Description |
---|
PausedExecutorService() |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long l,
TimeUnit timeUnit) |
void |
execute(Runnable command) |
boolean |
hasQueuedTasks() |
boolean |
isShutdown() |
boolean |
isTerminated() |
protected <T> RunnableFuture<T> |
newTaskFor(Callable<T> callable) |
protected <T> RunnableFuture<T> |
newTaskFor(Runnable runnable,
T value) |
int |
runAll()
Execute all posted tasks and block until they are complete.
|
boolean |
runNext()
Executes the next queued task.
|
void |
shutdown() |
List<Runnable> |
shutdownNow() |
public int runAll()
Execute all posted tasks and block until they are complete.
public boolean runNext()
Executes the next queued task.
Will be ignored if called from the executor service thread to prevent deadlocks.
public boolean hasQueuedTasks()
public void shutdown()
public boolean isShutdown()
public boolean isTerminated()
public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException
InterruptedException
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value)
newTaskFor
in class AbstractExecutorService
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
newTaskFor
in class AbstractExecutorService