Programmatic Jetty shutdown

前端 未结 3 971
别那么骄傲
别那么骄傲 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:35

    Having the ability for a Jetty server to be shutdown remotely through a HTTP request is not recommended as it provides as potential security threat. In most cases it should be sufficient to SSH to the hosting server and run an appropriate command there to shutdown a respective instance of a Jetty server.

    The basic idea is to start a separate thread as part of Jetty startup code (so there is no need to sleep as required in one of mentioned in the comment answers) that would serve as a service thread to handle shutdown requests. In this thread, a ServerSocket could be bound to localhost and a designated port, and when an expected message is received it would call server.stop().

    This blog post provides a detailed discussion using the above approach.

提交回复
热议问题