One common method currently utilized for this task is through "long polling", also referred to as Comet. This approach involves the browser sending a request to the server, which then maintains the connection until data is available to be sent back to the browser. For instance, on platforms like Gmail, the browser app might inquire about the next new message in the user's inbox, with the server delaying the response until the actual arrival of a new message.
Although technically initiated by the client, the concept behind long polling essentially allows the server to transmit data to the client at its own discretion in the future.
By employing long polling, servers often have numerous pending requests waiting idly. With the introduction of "asynchronous support" in Version 3 of the Servlet API, threads can now delay processing one request while attending to others. This enhanced functionality improves scalability compared to older versions where the service()
method had to tie up a thread until completing a response. Additionally, servlet containers such as Tomcat offer special extensions like Comet support for handling multiple requests concurrently using event-driven I/O.
While a newer protocol called WebSockets enables two-way communication over consistent connections without the HTTP overhead, it has yet to achieve widespread adoption.