Package org.opendaylight.yangtools.util
Class ExecutorServiceUtil
- java.lang.Object
-
- org.opendaylight.yangtools.util.ExecutorServiceUtil
-
public final class ExecutorServiceUtil extends Object
Utility methods for dealing withExecutorService
s.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> @NonNull BlockingQueue<E>
offerFailingBlockingQueue(BlockingQueue<E> delegate)
Creates aBlockingQueue
which does not allow for non-blocking addition to the queue.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.static @NonNull RejectedExecutionHandler
waitInQueueExecutionHandler()
Returns aRejectedExecutionHandler
which blocks on theThreadPoolExecutor
's backing queue if a new thread cannot be spawned.
-
-
-
Method Detail
-
offerFailingBlockingQueue
public static <E> @NonNull BlockingQueue<E> offerFailingBlockingQueue(BlockingQueue<E> delegate)
Creates aBlockingQueue
which does not allow for non-blocking addition to the queue. This is useful withwaitInQueueExecutionHandler()
to turn force aThreadPoolExecutor
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
-
waitInQueueExecutionHandler
public static @NonNull RejectedExecutionHandler waitInQueueExecutionHandler()
Returns aRejectedExecutionHandler
which blocks on theThreadPoolExecutor
'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.
-
-