java - Dropwizard Shutdown Hook -


the problem is, stop dropwizard application (via ctrl + c) , have inserted shutdown hook in main class stuff before shutdown. serverconnector application closed before can want do.

there polling service (polls 1 of resources) , need tell them, application go down prevent problems. need @ least 15 seconds before ressource goes down.

some idea how solve problem?

add dropwizard task change state of static field (or want pass data) polling resource using respond.

public class shutdowntask extends task {     private int timeoutseconds;      public shutdowntask (int timeoutseconds) {         super("shutdown");         this.timeoutseconds = timeoutseconds;     }        @override     public void execute(immutablemultimap<string, string> parameters, printwriter output) throws exception {         // can take timeout parameter request via 'parameters' instead of constructor.         pollingresource.shuttingdownin = timeoutseconds;     } }   environment.admin().addtask(new shutdowntask(15)); 

then write bash script curl task

curl -x post http://dw.example.com:8081/tasks/shutdown 

and:

  • this not recommended (people don't system.exit(0)) can add following execute method:

thread.sleep(timeoutseconds * 1000); system.exit(0)

  • or waiting , kill dropwizard app in bash script.

kill -sigint <pid>


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -