public static Thread addShutdownHook ( final AutoCloseable service , final String serviceName , final Logger logger ) { checkNotNull ( service ) ; checkNotNull ( logger ) ; final Thread shutdownHook = new Thread ( ( ) -> { try { service . close ( ) ; } catch ( Throwable t ) { logger . error ( "Error during shutdown of {} via JVM shutdown hook." , serviceName , t ) ; } } , serviceName + " shutdown hook" ) ; return addShutdownHookThread ( shutdownHook , serviceName , logger ) ? shutdownHook : null ; }
Adds a shutdown hook to the JVM and returns the Thread which has been registered .