I’m developing a web application with Spring and Tomcat 6. Sometimes, for some reason a request takes too long to complete and it reduces the server’s performance. Is it possible to limit the request execution time in Tomcat 6 or Spring? Other approaches on this problem are welcome. Thanks.
I’m developing a web application with Spring and Tomcat 6. Sometimes, for some reason
Share
Yes it is possible, but you would need to implement this yourself.
The basic idea is that the request method needs to use a
Timerto schedule an interrupt for itself for N seconds in the future. Then it needs to check periodically during the request processing to see if it has been interrupted. Finally, it needs to cancel the timer if it finishes before the timeout.The above assumes that it is the servlet should limit the time it spends processing a request. If instead you wanted to implement the timeout on the client side, it is easy to put timeout on the completion of a request; e.g. see Tomcat request timeout.
(But the problem with a client-side timeout is that the server won’t know that the client has given up waiting, and will keep processing the request regardless. It is easy to get into big problems with this. Imagine a request that takes a lot longer to complete than the timeout, combined with a client that repeatedly retries requests that it has timed out …)