Class ExecutorCloser

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class ExecutorCloser
    extends Object
    implements 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 Detail

      • ExecutorCloser

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

        public ExecutorCloser​(@Nullable
                              @Nullable ExecutorService executorService,
                              int timeout,
                              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