Dropwizard: How to stop service programmatically

前端 未结 5 772
花落未央
花落未央 2021-01-04 06:13

To start the service, I know one uses new MyService().run(args). How to stop it?

I need to start and stop programmatically for setUp() and

5条回答
  •  天命终不由人
    2021-01-04 07:01

    Or you use this java feature in your main/constructor ...:

        // In case jvm shutdown
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run()
            {
                // what should be closed if forced shudown
                // ....
    
                LOG.info(String.format("--- End of ShutDownHook (%s) ---", APPLICATION_NAME));
            }
        });
    

提交回复
热议问题