I am trying to process some business logic after user hit a URL. There will be a heavy loop running in server side. The browser will be loading (we can see the spinning animation on top) while waiting server return the result. 

We don't discuss is that correct or not to perform heavy loop in HTTP connection, my question is that, while the browser is waiting for the result, and, if user want to stop the processing, by closing the browser/tab or pressing ESCAPE or pressing the "X" cross button (at the browser bar), likely, the browser will stop to receive any data from server side. Now, my problem is, the server thread that is processing heavy loop will not stop somehow (even browser not to receive data anymore). How am I going to stop that?

I thought that, according TCP transmission, if one end of sockets is closed, another end will be notified and closed as well. I expect my server will have something like "socket close exception" thing thrown out by the `Servlet`. But it is not, so the loop in `Servlet` is still running until it finished. Any idea how can I stop it? It will lead to "Out of memory" issue if the user keep on hitting the URL and cancel the request.