What is the reason the servlet container interrupts the thread executing my HTTP request handler?
It depends on the container itself. It really is not standardized in the servlet specification.
Will it only do this when turned off?
Seems to be one of the most obvious reasons. Local tests taught me that at least Tomcat 7.0.22 and Glassfish 3.1.1 will immediately stop servlet processing, preventing them from continuing with their task. No exceptions will be thrown at this moment.
Will this be done when the client is not responding?
Only when request headers are not fully received. There is a timeout for connecting to a socket, which is usually 60 seconds. But if the request headers are not fully received, then your servlet method will not be introduced anyway. Only if the request header has fully arrived will your servlet method be introduced.
Then inside the servlet method; if the client provided the request body (for example, POST), and your servlet code starts reading the request body, for example, request.getParameter() or request.getInputStream() , then it will throw an IOException when the client interrupted sending the request body at the same time. On the other hand, when you write a response (and do a flash / commit), then an IOException will also be IOException when the client terminates the connection at this point. You can put it in a try-catch if necessary, but you can do nothing more than just log it. The usefulness of these protocols is very high and most likely will only clutter your server logs.
source share