Package org.apache.activemq.util
Class ThreadPoolUtils
java.lang.Object
org.apache.activemq.util.ThreadPoolUtils
Utility methods for working with thread pools
ExecutorService
.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
awaitTermination
(ExecutorService executorService) Awaits the termination of the thread pool indefinitely (Use with Caution).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.shutdownNow
(ExecutorService executorService) Shutdown now the given executor service aggressively.
-
Field Details
-
DEFAULT_SHUTDOWN_AWAIT_TERMINATION
public static final long DEFAULT_SHUTDOWN_AWAIT_TERMINATION- See Also:
-
-
Constructor Details
-
ThreadPoolUtils
public ThreadPoolUtils()
-
-
Method Details
-
shutdown
Shutdown the given executor service only (ie not graceful shutdown).- See Also:
-
shutdownNow
Shutdown now the given executor service aggressively.- Parameters:
executorService
- the executor service to shutdown now- Returns:
- list of tasks that never commenced execution
- See Also:
-
shutdownGraceful
Shutdown the given executor service graceful at first, and then aggressively if the await termination timeout was hit. This implementation invokes theshutdownGraceful(java.util.concurrent.ExecutorService, long)
with a timeout value ofDEFAULT_SHUTDOWN_AWAIT_TERMINATION
millis. -
shutdownGraceful
Shutdown the given executor service graceful at first, and then aggressively if the await termination timeout was hit. Will try to perform an orderly shutdown by giving the running threads time to complete tasks, before going more aggressively by doing ashutdownNow(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. If the shutdownAwaitTermination value is negative the shutdown waits indefinitely for the ExecutorService to complete its shutdown.- Parameters:
executorService
- the executor service to shutdownshutdownAwaitTermination
- timeout in millis to wait for orderly shutdown
-
awaitTermination
Awaits the termination of the thread pool indefinitely (Use with Caution). 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.- Parameters:
executorService
- the thread pool- Throws:
InterruptedException
- is thrown if we are interrupted during the waiting
-
awaitTermination
public static boolean awaitTermination(ExecutorService executorService, long shutdownAwaitTermination) throws InterruptedException Awaits the termination of the thread pool. 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.- Parameters:
executorService
- the thread poolshutdownAwaitTermination
- time in millis to use as timeout- Returns:
- true if the pool is terminated, or false if we timed out
- Throws:
InterruptedException
- is thrown if we are interrupted during the waiting
-