Reputation: 169
As per the various documentation available online eg this, I understand that with NIO mode maxConnections are not dependent on maxThreads parameter and each thread can serve any number of connections.
If I take a thread-dump, I get to see what all my threads are doing. Each of these threads is handling one request and this trace remains the same for long-running requests between multiple dumps taken in a quick interval, so how can these threads serve multiple request at the same time. I am using Tomcat v8.0.23, with Java v8.0.45.
"http-nio-8080-exec-35" #151 daemon prio=5 os_prio=0 tid=0x00007f5e70021000 nid=0x7337 runnable [0x00007f5f4ebe8000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
- locked <0x000000061d4a4070> (a java.io.BufferedInputStream)
at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:127)
Upvotes: 0
Views: 1247
Reputation: 16615
You have misunderstood.
Assuming we are only considering the synchronous, blocking Servlet API then Tomcat will support maxConnections but only maxThreads of those can be allocated to a processing thread at any one time.
The idea is that the majority of the connections will be essentially idle in HTTP keep-alive between requests. Hence a single Poller thread monitors these idle connections and passes them to a processing thread when there is data to process.
In earlier Tomcat releases, the BIO connector allocated 1 thread to a connection so that thread was in use even if the connection was idle which was inefficient.
Upvotes: 2