Today I fixed a bug in an application that might have lead to an endless loop in a servlet request/response cycle.
So just out of curiousity: What happens, if my servlet actually gets trapped in a for(;;) loop?
Is it somehow possible to recover? Will tomcat detect this? Can this instance be killed without restarting the server?
Or is this one of the worst things that can happen and a very quick way to kill a webcontainer?
EDIT: It was a true endless loop consuming CPU all the time but not memory. I kept it running for a few minutes. I think, I can confirm that tomcat will not detect this kind of thing :-)
I don't think that Tomcat will detect an infinite loop. You might be able to stop the servlet using the Tomcat manager, if the servlet is not consuming all the CPU time with its loop. Otherwise, it's probably safest and easiest to just restart the server.
This is why you do extensive tests locally before deploying your apps ;-) and be very careful that all your loops have exit conditions...
Not sure if Tomcat has such detection, but e.g Websphere's web container does. However, it obviously takes the container a relatively long time to detect a "hung" thread. Server under a load can be easily and quickly killed by such code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With