Class ExecutorServiceUtil


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

      • 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.
        Parameters:
        delegate - Backing blocking queue.
        Returns:
        A new blocking queue backed by the delegate
      • 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.