Class ExecutorServiceShutdownHook

  • All Implemented Interfaces:
    Runnable

    public class ExecutorServiceShutdownHook
    extends Thread
    The threads of executor services can cause a JVM to keep running if they are not daemon threads. Additionally, daemon threads can be interrupted by an unclean shutdown if no shutdown hook is provided. By using this implementation of a shutdown hook you get the best of both - threads stop at the correct time, not too soon and not too late.
    Author:
    AO Industries, Inc.
    • Constructor Detail

      • ExecutorServiceShutdownHook

        public ExecutorServiceShutdownHook​(ExecutorService executorService)
        Creates a new shutdown hook.
      • ExecutorServiceShutdownHook

        public ExecutorServiceShutdownHook​(ExecutorService executorService,
                                           long shutdownTimeout,
                                           TimeUnit shutdownTimeoutUnit)
        Creates a new shutdown hook.
      • ExecutorServiceShutdownHook

        public ExecutorServiceShutdownHook​(ExecutorService executorService,
                                           String threadName)
        Creates a new shutdown hook.
      • ExecutorServiceShutdownHook

        public ExecutorServiceShutdownHook​(ExecutorService executorService,
                                           String threadName,
                                           long shutdownTimeout,
                                           TimeUnit shutdownTimeoutUnit)
        Creates a new shutdown hook.
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface Runnable
        Overrides:
        run in class Thread