public static boolean addShutdownHookThread(
		final Thread shutdownHook,
		final String serviceName,
		final Logger logger) {

		checkNotNull(shutdownHook);
		checkNotNull(logger);

		try {
			// Add JVM shutdown hook to call shutdown of service
			Runtime.getRuntime().addShutdownHook(shutdownHook);
			return true;
		} catch (IllegalStateException e) {
			// JVM is already shutting down. no need to do our work
		} catch (Throwable t) {
			logger.error("Cannot register shutdown hook that cleanly terminates {}.", serviceName, t);
		}
		return false;
	}
public static boolean addShutdownHookThread ( final Thread shutdownHook , final String serviceName , final Logger logger ) { checkNotNull ( shutdownHook ) ; checkNotNull ( logger ) ; try { Runtime . getRuntime ( ) . addShutdownHook ( shutdownHook ) ; return true ; } catch ( IllegalStateException e ) { } catch ( Throwable t ) { logger . error ( "Cannot register shutdown hook that cleanly terminates {}." , serviceName , t ) ; } return false ; }
Adds a shutdown hook to the JVM.

@param shutdownHook Shutdown hook to be registered.
@param serviceName The name of service.
@param logger The logger to log.
@return Whether the hook has been successfully registered.