public static void stopService ( ) { DaemonStarter . currentPhase . set ( LifecyclePhase . STOPPING ) ; final CountDownLatch cdl = new CountDownLatch ( 1 ) ; Executors . newSingleThreadExecutor ( ) . execute ( ( ) -> { DaemonStarter . getLifecycleListener ( ) . stopping ( ) ; DaemonStarter . daemon . stop ( ) ; cdl . countDown ( ) ; } ) ; try { int timeout = DaemonStarter . lifecycleListener . get ( ) . getShutdownTimeoutSeconds ( ) ; if ( ! cdl . await ( timeout , TimeUnit . SECONDS ) ) { DaemonStarter . rlog . error ( "Failed to stop gracefully" ) ; DaemonStarter . abortSystem ( ) ; } } catch ( InterruptedException e ) { DaemonStarter . rlog . error ( "Failure awaiting stop" , e ) ; Thread . currentThread ( ) . interrupt ( ) ; } }
Stop the service and end the program