java - What is the best way to make a Jetty server do something before shutting down? -


i have jetty server being initialized , started this:

    server server = new server(50001);       myhandler myhandler = new myhandler();     server.sethandler(myhandler);       // attempt run server     try {         server.start();         server.join();     } catch (exception e) {         logger.warning(e.getmessage());         system.exit(2);     } 

the class myhandler has method called shutdown waits tasks complete. myhandler.shutdown() invoked before server shutdown.

i have considered using runtime.getruntime().addshutdownhook(), not sure of best way pass myhandler it, , suspect there must cleaner way this.

i looking best way this.

thanks!

follow handler chain down , you'll see runs abstractlifecycle defines methods called dostart() , dostop(). can override these plug lifecycle of server instance since adding handler server. works either extends abstractlifecycle or implements lifecycle, making handy mechanism register start , stop type behaviors. dostart() called in processing of server.start() , dostop() called during processing of server.stop() call.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -