Class PausedExecutorService

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService

    @Beta
    public class PausedExecutorService
    extends java.util.concurrent.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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean awaitTermination​(long l, java.util.concurrent.TimeUnit timeUnit)  
      void execute​(java.lang.Runnable command)  
      boolean hasQueuedTasks()  
      boolean isShutdown()  
      boolean isTerminated()  
      protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor​(java.lang.Runnable runnable, T value)  
      protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor​(java.util.concurrent.Callable<T> callable)  
      int runAll()
      Execute all posted tasks and block until they are complete.
      boolean runNext()
      Executes the next queued task.
      void shutdown()  
      java.util.List<java.lang.Runnable> shutdownNow()  
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

        invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PausedExecutorService

        public PausedExecutorService()
    • 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()
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
      • isShutdown

        public boolean isShutdown()
      • isTerminated

        public boolean isTerminated()
      • awaitTermination

        public boolean awaitTermination​(long l,
                                        java.util.concurrent.TimeUnit timeUnit)
                                 throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • execute

        public void execute​(@NonNull
                            java.lang.Runnable command)
      • newTaskFor

        protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor​(java.lang.Runnable runnable,
                                                                        T value)
        Overrides:
        newTaskFor in class java.util.concurrent.AbstractExecutorService
      • newTaskFor

        protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor​(java.util.concurrent.Callable<T> callable)
        Overrides:
        newTaskFor in class java.util.concurrent.AbstractExecutorService