With NIO connector set in Tomcat we have N pooler threads and M worker threads.

With BIO connector set we can have N*M threads in thread pool. So what will be the difference between two connectors ?

1 Answers

0
Mark Thomas On Best Solutions

In BIO each new connection is allocated a thread from the Connector thread pool and that thread stays assigned to that connection until the connection closes. This means threads are idle for long periods of time between requests (i.e. during HTTP keep-alive).

In NIO, each new connection is passed to the Poller. A Poller thread is notified when there is data on the connection to be processed. The Poller then allocates a thread to the connection from the Connector thread pool and that thread stays assigned to that connection until all the data has been read/written. The connection is then passed back to the Poller so the Poller can monitor for more data.

In short, this makes NIO more scaleable. BIO requires one thread in the thread pool for each connection. NIO can maintain many more connections than BIO and only requires one thread in the thread pool for each concurrently processed request.