Class ImmediateExecutorService

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

    public final class ImmediateExecutorService
    extends java.util.concurrent.AbstractExecutorService
    Simple implementation of ExecutorService which runs all tasks on thread the call was made from

    This is useful as a quick implementation, and should be used only when blocking is fine

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean awaitTermination​(long timeout, java.util.concurrent.TimeUnit unit)
      No-op
      void execute​(java.lang.Runnable command)
      Immediately runs the passed command, unless shutdown flag is set If shutdown flag is set, this is a no-op
      boolean isShutdown()
      Returns the shutdown flag set by shutdown() and shutdownNow()
      boolean isTerminated()
      Returns the shutdown flag set by shutdown() and shutdownNow()
      void shutdown()
      Sets the shutdown flag just for isShutdown() and isTerminated() methods
      java.util.List<java.lang.Runnable> shutdownNow()
      Returns an empty list of runnables, since it can't hold any and sets the same flag as shutdown()
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

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

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

      • ImmediateExecutorService

        public ImmediateExecutorService()
    • Method Detail

      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
        Returns an empty list of runnables, since it can't hold any and sets the same flag as shutdown()
        Returns:
        an empty list
      • isShutdown

        public boolean isShutdown()
        Returns the shutdown flag set by shutdown() and shutdownNow()
        Returns:
        shutdown flag
      • isTerminated

        public boolean isTerminated()
        Returns the shutdown flag set by shutdown() and shutdownNow()
        Returns:
        shutdown flag
      • awaitTermination

        public boolean awaitTermination​(long timeout,
                                        java.util.concurrent.TimeUnit unit)
                                 throws java.lang.InterruptedException
        No-op
        Returns:
        true
        Throws:
        java.lang.InterruptedException
      • execute

        public void execute​(java.lang.Runnable command)
        Immediately runs the passed command, unless shutdown flag is set If shutdown flag is set, this is a no-op
        Parameters:
        command - to run