@ Override final public void run ( ) { // name current thread for improved logging/debugging Thread . currentThread ( ) . setName ( this . name ) ; try { this . configure ( ) ; } catch ( Exception e ) { logger . error ( "Unable to configure {}" , name , e ) ; System . exit ( 1 ) ; } try { this . start ( ) ; } catch ( Exception e ) { logger . error ( "Unable to start {}" , name , e ) ; System . exit ( 1 ) ; } Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) { @ Override public void run ( ) { shutdown ( ) ; } } ) ; try { // do not simply exit main() -- join something (likely server) join ( ) ; } catch ( Exception e ) { logger . warn ( "Interrupted (most likely JVM is shutting down and this is safe to ignore)" ) ; } }
Configure start add shutdown hook and join . Does not exit .