views:

60

answers:

1

When my tomcat (6.0.20) maxThreads limit is reached, i get the expected error:

Maximum number of threads (XXX) created for connector with address null and port 80

And then request starts hanging on queue and eventually timing out. so far, so good. The problem is that when the load goes down, the server does not recover and is forever paralysed, instead of coming back to life.

Any hints?

+5  A: 

Consider switching to NIO, then you don't need to worry about the technical requirement of 1 thread per connection. Without NIO, the limit is about 5K threads (5K HTTP connections), then it blows like that. With NIO, Java will be able to manage multiple resources by a single thread, so the limit is much higher. The border is practically the available heap memory, with about 2GB you can go up to 20K connections.

Configuring Tomcat to use NIO is as simple as changing the protocol attribute of the <Connector> element in /conf/server.xml to "org.apache.coyote.http11.Http11NioProtocol".

BalusC
I have considered that, but i don't know if that would damage classes that rely on ThreadLocal, like Spring OpenSessionInViewFilter.
Julio Faerman
If those classes are well-written that it uses `ThreadLocal#remove()` the right way, then I don't forsee problems. Even more, threads for HTTP servlet requests are already by default pooled. In real world production environments, NIO is more than often standard turned on.
BalusC
@Julio Faerman it doesn't
nos
+1 this is a way to solve it. Not sure to the orig question on why it doesn't recover.. id say some kind of bug in how unused threads are killed off, leading to some kind of livelock or such
bwawok
There is still only a single thread per request. NIO just means that you have multiple threads per HTTP connection, rather than just one.
Javid Jamae
Will do it. Thanks a lot.
Julio Faerman
It is working, but i am stil puzzled of why it does not recover....
Julio Faerman