Class ExecutorCloser

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class ExecutorCloser
    extends java.lang.Object
    implements java.io.Closeable

    Utility class to properly close any ExecutorService.

    It will attempt a graceful close within the provided timeout. If after such any of the contained tasks are not terminated yet, it will force a shutdown and track a warning in the logs.

    • Constructor Summary

      Constructors 
      Constructor Description
      ExecutorCloser​(@Nullable java.util.concurrent.ExecutorService executorService)
      will attempt a graceful close in 5 seconds
      ExecutorCloser​(@Nullable java.util.concurrent.ExecutorService executorService, int timeout, java.util.concurrent.TimeUnit unit)
      will attempt a graceful close by the provided time.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExecutorCloser

        public ExecutorCloser​(@Nullable
                              @Nullable java.util.concurrent.ExecutorService executorService)
        will attempt a graceful close in 5 seconds
        Parameters:
        executorService -
      • ExecutorCloser

        public ExecutorCloser​(@Nullable
                              @Nullable java.util.concurrent.ExecutorService executorService,
                              int timeout,
                              java.util.concurrent.TimeUnit unit)
        will attempt a graceful close by the provided time.
        Parameters:
        executorService - the executor to close
        timeout - the time to wait for
        unit - the unit of time
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable