Class PausedExecutorService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- org.robolectric.android.util.concurrent.PausedExecutorService
-
- All Implemented Interfaces:
Executor
,ExecutorService
@Beta public class PausedExecutorService extends AbstractExecutorService
Executor service that queues any posted tasks. Users must explicitly callrunAll()
to execute all pending tasks. Intended to be a replacement forRoboExecutorService
when usingLooperMode.Mode.PAUSED
. UnlikeRoboExecutorService
, 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 Summary
Constructors Constructor Description PausedExecutorService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long l, TimeUnit timeUnit)
void
execute(Runnable command)
boolean
hasQueuedTasks()
boolean
isShutdown()
boolean
isTerminated()
protected <T> RunnableFuture<T>
newTaskFor(Runnable runnable, T value)
protected <T> RunnableFuture<T>
newTaskFor(Callable<T> callable)
int
runAll()
Execute all posted tasks and block until they are complete.boolean
runNext()
Executes the next queued task.void
shutdown()
List<Runnable>
shutdownNow()
-
-
-
Method Detail
-
runAll
public int runAll()
Execute all posted tasks and block until they are complete.- Returns:
- the number of tasks executed
-
runNext
public boolean runNext()
Executes the next queued task. Will be ignored if called from the executor service thread to prevent deadlocks.- Returns:
- true if task was run, false if queue was empty
-
hasQueuedTasks
public boolean hasQueuedTasks()
- Returns:
- true if there are queued pending tasks
-
shutdown
public void shutdown()
-
isShutdown
public boolean isShutdown()
-
isTerminated
public boolean isTerminated()
-
awaitTermination
public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException
- Throws:
InterruptedException
-
execute
public void execute(@NonNull Runnable command)
-
newTaskFor
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value)
- Overrides:
newTaskFor
in classAbstractExecutorService
-
newTaskFor
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
- Overrides:
newTaskFor
in classAbstractExecutorService
-
-