类 GracefulExecutorServicesShutdown

java.lang.Object
org.apache.pulsar.common.util.GracefulExecutorServicesShutdown

public class GracefulExecutorServicesShutdown extends Object
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.
  • 方法详细资料

    • initiate

      public static GracefulExecutorServicesShutdown initiate()
      Initiates a new shutdown for one or many ExecutorServices.
      返回:
      a new instance for controlling graceful shutdown
    • shutdown

      public GracefulExecutorServicesShutdown shutdown(ExecutorService... executorServices)
      Calls ExecutorService.shutdown() and enlists the executor as part of the shutdown handling.
      参数:
      executorServices - one or many executors to shutdown
      返回:
      the current instance for controlling graceful shutdown
    • timeout

      public GracefulExecutorServicesShutdown timeout(Duration timeout)
      Sets the timeout for graceful shutdown.
      参数:
      timeout - duration for the timeout
      返回:
      the current instance for controlling graceful shutdown
    • terminationTimeout

      public GracefulExecutorServicesShutdown terminationTimeout(Duration terminationTimeout)
      Sets the timeout for waiting for executors to complete in forceful termination.
      参数:
      terminationTimeout - duration for the timeout
      返回:
      the current instance for controlling graceful shutdown
    • handle

      public CompletableFuture<Void> 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 calling ExecutorService.shutdownNow().
      返回:
      a future which completes when all executors have terminated