Package org.apache.pulsar.common.util
Class GracefulExecutorServicesShutdown
java.lang.Object
org.apache.pulsar.common.util.GracefulExecutorServicesShutdown
This a builder like class for providing a fluent API for graceful shutdown
Executors are added with the
shutdown(ExecutorService...)
method. The ExecutorService.shutdown() method is called immediately.
Calling the handle() method returns a future which completes when all executors
have been terminated.
The executors will waited for completion with the ExecutorService.awaitTermination(long, TimeUnit) method.
If the shutdown times out or the future is cancelled, all executors will be terminated and the termination
timeout value will be used for waiting for termination.
The default value for termination timeout is 10% of the shutdown timeout.-
Method Summary
Modifier and TypeMethodDescriptionhandle()Starts the handler for polling frequently for the completed termination of enlisted executors.initiate()Initiates a new shutdown for one or manyExecutorServices.shutdown(ExecutorService... executorServices) CallsExecutorService.shutdown()and enlists the executor as part of the shutdown handling.terminationTimeout(Duration terminationTimeout) Sets the timeout for waiting for executors to complete in forceful termination.Sets the timeout for graceful shutdown.
-
Method Details
-
initiate
Initiates a new shutdown for one or manyExecutorServices.- Returns:
- a new instance for controlling graceful shutdown
-
shutdown
CallsExecutorService.shutdown()and enlists the executor as part of the shutdown handling.- Parameters:
executorServices- one or many executors to shutdown- Returns:
- the current instance for controlling graceful shutdown
-
timeout
Sets the timeout for graceful shutdown.- Parameters:
timeout- duration for the timeout- Returns:
- the current instance for controlling graceful shutdown
-
terminationTimeout
Sets the timeout for waiting for executors to complete in forceful termination.- Parameters:
terminationTimeout- duration for the timeout- Returns:
- the current instance for controlling graceful shutdown
-
handle
Starts the handler for polling frequently for the completed termination of enlisted executors. If the termination times out or the future is cancelled, all active executors will be forcefully terminated by callingExecutorService.shutdownNow().- Returns:
- a future which completes when all executors have terminated
-