Tomcat and Connection Handling  
Author Message
fritz-bayer@web.de





PostPosted: 2006-4-1 22:01:00 Top

java-programmer, Tomcat and Connection Handling Hi,

I have noticed that when you do not return from the doGet() or doPost()
method, for example, by inserting a infinite while loop like this:

public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException
{
while(true);
}

that tomcat will run out of connections after a few requests. So it
seems to me, that tomcat is only using a few threads to serve many many
http requests.

Is there any way that I can make sure, that each doGet() and doPost()
will be handle by a dedicated thread?

The problem I'm trying to solve is to keep up to 1000 http connections
alive over a long period of time and to sent information to the clients
once in a while.

I have solved this with basic thread blocking and waiting on objects,
but the problem is that tomcat runs out of threads, because there seems
to be a limited amount of threads, which tomcat uses to serve its http
requests.

any advice is appreciated!
fritz

 
Frank Dannhauer





PostPosted: 2006-4-2 2:51:00 Top

java-programmer >> Tomcat and Connection Handling email***@***.com wrote:
> [...] So it
> seems to me, that tomcat is only using a few threads to serve many many
> http requests.

See http://tomcat.apache.org/tomcat-5.5-doc/config/http.html (maxThreads)


> The problem I'm trying to solve is to keep up to 1000 http connections
> alive over a long period of time and to sent information to the clients
> once in a while.

Why would you do this?


Greetings,

Frank
 
fritz-bayer@web.de





PostPosted: 2006-4-2 4:20:00 Top

java-programmer >> Tomcat and Connection Handling Hi Frank,

thanks for the tomcat pages, but I know all the docs. I'm using tomcat
4.1 but I also tried it with 5.5 and it does not work.

If you program a chat, for example, then you need this behaviour. I
know you could do it differently, but if your client only support html
and http, then you have no choice.

So you have for example 400 clients connected and if one of them sends
a request with a message, you forward it to all other clients.

Problem I have is that I run out of threads after just a few
connections. I don't really understand why this happens. Here is the
connector, which I use:

<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8080" minProcessors="5" maxProcessors="400"
enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="20000"
useURIValidationHack="false" disableUploadTimeout="true"
/>

 
 
Tony Morris





PostPosted: 2006-4-2 5:52:00 Top

java-programmer >> Tomcat and Connection Handling > that tomcat will run out of connections after a few requests. So it
> seems to me, that tomcat is only using a few threads to serve many many
> http requests.

That sounds to me like an optimal behaviour as a result of thread
pooling. I'd expect something like this from Tomcat. Were you expecting
something else? I'd take a look around the documentation for finding how
how it handles requests behind the spec. implementation - it is almost
certainly pulling from a (configurable?) pool.

--
Tony Morris
http://tmorris.net/

s/Commonwealth Games/Commonwealth Swimming
 
 
fritz-bayer@web.de





PostPosted: 2006-4-2 17:00:00 Top

java-programmer >> Tomcat and Connection Handling
Tony Morris wrote:
> > that tomcat will run out of connections after a few requests. So it
> > seems to me, that tomcat is only using a few threads to serve many many
> > http requests.
>
> That sounds to me like an optimal behaviour as a result of thread
> pooling. I'd expect something like this from Tomcat. Were you expecting
> something else? I'd take a look around the documentation for finding how
> how it handles requests behind the spec. implementation - it is almost
> certainly pulling from a (configurable?) pool.
>
> --
> Tony Morris
> http://tmorris.net/
>
> s/Commonwealth Games/Commonwealth Swimming

Well, I'm expecting that tomcat dedicates one thread to each requests
it handles. Anything else would be problematic in my opinion, because
if you use thread programming to communicate between objects you will
run out of threads, which is very bad.

But I just found out, that Tomcat is actually doing everything right.
It's the firefox Browser, which I'm using that's to blame. It seems to
have problems with my application. Conquerer and other Browsers do not
yield the same problems. So I guess this question is closed.