Search code examples
javajetty

How does a Java web server, like Jetty, continually listen for new connections without terminating in main?


I was trying to understand the "best practices" for preventing a program from terminating in main, using a Jetty web server as an example.

Where can I find the code in Jetty that loops constantly waiting for a connection? Is Jetty essentially using a while(true) loop somewhere? Or is there a more effective method to preventing the web server from terminating in main?


Solution

  • Jetty uses Java NIO to handle all Networking (listening, accepting, reading, writing, closing, etc).

    See other answer on details about NIO accept.

    How java nio ServerSocketChannel accept works?