The moose likes Servlets and the fly likes How to extend timeout / keepalive timeout in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to extend timeout / keepalive timeout in Tomcat" Watch "How to extend timeout / keepalive timeout in Tomcat" New topic

How to extend timeout / keepalive timeout in Tomcat

Jonathan Ortiga

Joined: Jan 14, 2002
Posts: 4
Hi Guys,
have a long running transaction done via web.
it takes around 20 mins plus to complete.
problem is my browser is timing out. I am using
tomcat 3.3 as webserver and have already adjusted
the timeout conf var in the server.xml and prof-server.xml file to 50000 (more than enough). But still my browser gets a timeout error when running the transaction. I am using IE5.
i wish NOT to integrate my tomcat webserver with apache. just like to use tomcat as is. I think I just missed something in my tomcat conf.
do you have any idea how to fix this?
thanks very much...
Pritam Banerjee

Joined: May 08, 2002
Posts: 9
There is a common soltion to this problem of timeout. That has got nothing to do with the web/ application server you host your servlets. It will work everywhere.
You have to write a Thread of your own. Pseudo code as follows:
class KeepAliveThread extends Thread{
PrintWriter out;
boolean stillProcessing;
KeepAliveThread(PrintWriter out){
this.out = out;
stillProcessing = true;
public void run(){
out.write(" ");
catch(InterruptedException e){}


Now your doPost() or doGet() in your servlet code should be like this:
public void doPost(HttpServletRequest req, HttpServletResponse resp){
//start the thread that sends sapces to keep connection alive with the browser
PrintWriter out = resp.getWriter();
KeepAliveThread kth = new KeepAliveTHread(out);
//do Processing by calling other methods etc
//end proc essing, before displaying the results or before forwarding to a JSP
kth.stillProcessing = false;
// Now display the results
Since HTML ignores all spaces before <HTML> tag, the display will be perfect and you can be sure that the browser will never timeout, even if the processing takes hours.
This solution will work in any platform.
Jonathan Ortiga

Joined: Jan 14, 2002
Posts: 4
Hi Pritam,
Thanks for the help... But it did not fix my problem. I am still getting the same problem... this is the same error i am getting earlier... Only this time it took approx 2 min longer before I got the error...
I am using NT4 as OS and IE5/NS4 for browser... any other ideas would be very helpful...

Problem Report
There was a communication problem.
Message ID
The system was unable to communicate with the server.
Possible Problem
The Web server may be down.
The Web server may be too busy.
The Web server may be experiencing other problems, preventing
it from responding to clients.
The communication path may be experiencing problems.
Possible Solution
Try connecting to this server later.
Pritam Banerjee

Joined: May 08, 2002
Posts: 9
Actually this is the way we solved the same problem in one of our applications.
Are you sure that the thread you start at the start of the servlet is actually running. You can probably send '.' (dots) instead of space and check out if you get them (the dots) in the browser. If the browser is continously getting something (even if blank spaces) there is no reason why it shoud timeout.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951

If you're trying to run an application in a web browser like it was a client/server app, you're just begging for trouble. First of all, if you're REALLY submitting a request from a browser window and expecting it to sit there for 20 minutes, I wonder that you've succeeded even as well as you have - 2 or 3 minutes is about as long as I expect a browser to wait - the whole DESIGN of a browser is for interactive use, not something that just parks there forever.
Tweaking parms on a server isn't going to help anyway - it's the browser that makes the call on timeout, and unless someone's slipped something by when I wasn't looking, there's no message a server can send back saying "hold on, I'll be taking a while". After all, the idea is to respond as soon as possible!
Long-running tasks are hardly impossible in the HTTP world - I've done some myself. But the idea is to kick them off and then let the user check back as needed, so that he/she can do other things in the mean time. Besides, what happens when the browser/OS crashes after 18 minutes of processing? Such things still happen, even if not as often as in earlier times.

Customer surveys are for companies who didn't pay proper attention to begin with.
Jonathan Ortiga

Joined: Jan 14, 2002
Posts: 4
Hi Guys,
I can see I am getting a lot of help here... really appreciate it. thanks.
now, going back to the problem. Actually, I tried sending numbers 1...n to the browser. And I can see that it's received by the browser. This I tried for transactions taking 2 - 3 mins only. I verified the html source delivered by the server to the browser... it's there.

Sad to say, it's really timing out for long running transactions.
I am now thinking of using that keepalive thread class to return a message to the stream saying something like "the browser is going to time out but the transaction is gonna continue running on the server. please check again later.." if the transaction runs for more than two minutes. I know that this is really not a good approach so it would be really nice if we could solve the problem on the timeout. thanks.
Consider Paul's rocket mass heater.
subject: How to extend timeout / keepalive timeout in Tomcat
Similar Threads
Tomcat doesn't stop
ConnectionTimeOut Vs sessionTimeout problem
need clarification on instruction to set up mod_jk.dll
setTransactionTimeout in CMP