voipp
voipp

Reputation: 1445

What is fundamental difference between NIO and BIO in Tomcat?

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 ?

Upvotes: 8

Views: 7297

Answers (1)

Mark Thomas
Mark Thomas

Reputation: 16625

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.

Upvotes: 14

Related Questions