public final class ThreadPoolUtils extends Object
ExecutorService
.Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_SHUTDOWN_AWAIT_TERMINATION |
Constructor and Description |
---|
ThreadPoolUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
awaitTermination(ExecutorService executorService,
long shutdownAwaitTermination)
Awaits the termination of the thread pool.
|
static void |
shutdown(ExecutorService executorService)
Shutdown the given executor service only (ie not graceful shutdown).
|
static void |
shutdownGraceful(ExecutorService executorService)
Shutdown the given executor service graceful at first, and then aggressively if the await
termination timeout was hit.
|
static void |
shutdownGraceful(ExecutorService executorService,
long shutdownAwaitTermination)
Shutdown the given executor service graceful at first, and then aggressively if the await
termination timeout was hit.
|
static List<Runnable> |
shutdownNow(ExecutorService executorService)
Shutdown now the given executor service aggressively.
|
public static final long DEFAULT_SHUTDOWN_AWAIT_TERMINATION
public static void shutdown(ExecutorService executorService)
executorService
- The ExecutorService that is being shutdown.ExecutorService.shutdown()
public static List<Runnable> shutdownNow(ExecutorService executorService)
executorService
- the executor service to shutdown nowExecutorService.shutdownNow()
public static void shutdownGraceful(ExecutorService executorService)
This implementation invokes the
shutdownGraceful(java.util.concurrent.ExecutorService, long)
with a timeout
value of DEFAULT_SHUTDOWN_AWAIT_TERMINATION
millis.
executorService
- The ExecutorService that is being shutdown.public static void shutdownGraceful(ExecutorService executorService, long shutdownAwaitTermination)
Will try to perform an orderly shutdown by giving the running threads time to complete
tasks, before going more aggressively by doing a
shutdownNow(java.util.concurrent.ExecutorService)
which forces a shutdown. The
parameter shutdownAwaitTermination is used as timeout value waiting for orderly
shutdown to complete normally, before going aggressively.
executorService
- the executor service to shutdownshutdownAwaitTermination
- timeout in millis to wait for orderly shutdownpublic static boolean awaitTermination(ExecutorService executorService, long shutdownAwaitTermination) throws InterruptedException
This implementation will log every 2nd second at INFO level that we are waiting, so the end user can see we are not hanging in case it takes longer time to terminate the pool.
executorService
- the thread poolshutdownAwaitTermination
- time in millis to use as timeoutInterruptedException
- is thrown if we are interrupted during the waitingCopyright © 2013–2016 The Apache Software Foundation. All rights reserved.