grizzly http server should keep running

后端 未结 3 605
有刺的猬
有刺的猬 2020-12-29 10:49

Below is the code to start Grizzly Http Server. If I press any key the server stops. Is there any way to keep it alive.

Jetty has join() method, which will not exit

3条回答
  •  有刺的猬
    2020-12-29 11:18

    The server stops because you call the httpServer.stop() method after the input stream. When the execution reachs the System.in.read(); it hangs till you enter a letter and then moves on to the server stop.

    You can just comment httpServer.stop() because that code example is exactly to hang up the server when a key is pressed.

    But if you want to create a Webserver instance I would suggest that you run a Thread in main() that starts an instance of the Grizzly Webserver.

提交回复
热议问题