Package org.opendaylight.yangtools.util
Class ExecutorServiceUtil
java.lang.Object
org.opendaylight.yangtools.util.ExecutorServiceUtil
Utility methods for dealing with
ExecutorService
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic <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
Returns aRejectedExecutionHandler
which blocks on theThreadPoolExecutor
's backing queue if a new thread cannot be spawned.
-
Method Details
-
offerFailingBlockingQueue
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.- Type Parameters:
E
- type of elements- Parameters:
delegate
- Backing blocking queue.- Returns:
- A new blocking queue backed by the delegate
-
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.- Parameters:
executor
- Executor to shut downtimeout
- timeout periodunit
- timeout unit
-