public static void addShutdownHook ( final Thread shutdownHook ) { Object token = ThreadIdentityManager . runAsServer ( ) ; try { AccessController . doPrivileged ( new PrivilegedAction < Void > ( ) { @ Override public Void run ( ) { Runtime . getRuntime ( ) . addShutdownHook ( shutdownHook ) ; return null ; // Nothing to return } } ) ; } finally { ThreadIdentityManager . reset ( token ) ; } }
Add a shutdown hook as a privileged action .