How can I set timeout for servlet response?

reshma deshmukh

[More info: I.e. if servlet not gives answers for 1 min. (it freezes, it makes too long SQL query etc), browser will receive some error message.

I work with resin servlet engine, but if it is impossible in resin, solutions for other engines also are welcome.

Of course, I can do this manualy (Timer, or just Thread with sleep()) but solution at config level is preferable.

Thanx]

For HTTP1.1 you can set status codes for response. (some browsers support for 1.0 also) You can call response.setStatus before sending any content via the PrintWriter.

For setting timeout , status code is "SC_GATEWAY_TIMEOUT" with value 504. You can call response.setStatus(504)for that. You call call response.sendError also. The advantage of sendError over setStatus is that, with sendError, the server automatically generates an error page showing the error message. In your case it will be :

response.sendError(response.SC_GATEWAY_TIMEOUT,
                       "Timeout");
[That doesn't answer the question directly; you still need to implement your own timeout in your servlet code before sending the 504 response. Is there a standard way to configure this irrespective of servlet code? -Alex]
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact