Programmatic Jetty shutdown

前端 未结 3 980
别那么骄傲
别那么骄傲 2021-02-06 08:08

How to programmatically shutdown embedded jetty server?

I start jetty server like this:

Server server = new Server(8090);
...
server.start();
server.joi         


        
3条回答
  •  悲哀的现实
    2021-02-06 08:21

    I found a very clean neat method here

    The magic code snippet is:-

            server.setStopTimeout(10000L);;
            try {
                new Thread() {
                    @Override
                    public void run() {
                        try {
                            context.stop();
                            server.stop();
                        } catch (Exception ex) {
                            System.out.println("Failed to stop Jetty");
                        }
                    }
                }.start();
    

    Because the shutdown is running from a separate thread, it does not trip up over itself.

提交回复
热议问题