Class ExecutorServiceUtil

java.lang.Object
org.opendaylight.yangtools.util.ExecutorServiceUtil

public final class ExecutorServiceUtil extends Object
Utility methods for dealing with ExecutorServices.
  • Method Details

    • offerFailingBlockingQueue

      public static <E> @NonNull BlockingQueue<E> offerFailingBlockingQueue(BlockingQueue<E> delegate)
      Creates a BlockingQueue which does not allow for non-blocking addition to the queue. This is useful with waitInQueueExecutionHandler() to turn force a ThreadPoolExecutor to create as many threads as it is configured to before starting to fill the queue.
      Type Parameters:
      E - type of elements
      Parameters:
      delegate - Backing blocking queue.
      Returns:
      A new blocking queue backed by the delegate
    • waitInQueueExecutionHandler

      public static @NonNull RejectedExecutionHandler waitInQueueExecutionHandler()
      Returns a RejectedExecutionHandler which blocks on the ThreadPoolExecutor's backing queue if a new thread cannot be spawned.
      Returns:
      A shared RejectedExecutionHandler instance.
    • tryGracefulShutdown

      public static void tryGracefulShutdown(@NonNull ExecutorService executor, long timeout, @NonNull TimeUnit unit)
      Tries to shutdown the given executor gracefully by awaiting termination for the given timeout period. If the timeout elapses before termination, the executor is forcefully shutdown.
      Parameters:
      executor - Executor to shut down
      timeout - timeout period
      unit - timeout unit