Class CloseableExecutor

  • All Implemented Interfaces:
    AutoCloseable

    public class CloseableExecutor
    extends Object
    implements AutoCloseable
    AutoCloseable wrapper around an executor.

    This shuts down the wrapped executor when it is closed, and can wait for tasks to exit.

    • Method Detail

      • of

        public static CloseableExecutor of​(ExecutorService executor)
        Returns a closeable executor that wraps a passed in executor.

        The passed in executor is shut down when the returned CloseableExecutor is closed.

        Parameters:
        executor - the executor to wrap
        Returns:
        a CloseableExecutor
      • of

        public static CloseableExecutor of​(ExecutorService executor,
                                           Duration duration)
        Returns a closeable executor that wraps a passed in executor.

        The passed in executor is shut down when the returned CloseableExecutor is closed, and waits for the given duration for tasks to finish.

        Parameters:
        executor - the executor to wrap
        duration - the duration to wait for tasks to exit
        Returns:
        a CloseableExecutor