How to limit the request execution time with Tomcat 6 How to limit the request execution time with Tomcat 6 spring spring

How to limit the request execution time with Tomcat 6


Using the HttpConnector configuration connectionTimeout

modify your server.xml

<Connector ... connectionTimeout="xxxx"

where xxxx is amount of milliseconds


Is it possible to limit the request execution time in Tomcat 6 or Spring?

Yes it is possible, but you would need to implement this yourself.

The basic idea is that the request method needs to use a Timer to 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 ...)


The above statement by Sthepen is not correct. On client side, when it gives up or the browswer is closed the browser does not of course keep it's socket alive. It does a socket shutdown (recover the memory and the port, right?). The shutdown procedure will send the laid down signals to the server side socket - RST i believe.