Hello I am fairly new to Tomcat and I want to know if NIO is really non-blocking.
From my own research, I’ve learned that under the NIO model the poller is responsible for managing connections in the poller event queue and Tomcat I/O threads will get notified upon receipt of a request. Once the Tomcat I/O thread processes the request and writes the response back to the socket, it goes back to the tread pool for more request processing as opposed to BIO where the Tomcat I/O thread hangs waiting for the next request unless Connection: close is specified in a request header. This makes NIO more scalable than BIO as NIO can handle more connections than its thread capacity
But what if the Tomcat I/O makes a network request that takes some time?
Let’s say, for example, I have an /hello API that makes a network request that takes 3 seconds to respond. I have allocated 1 thread to the Tomcat I/O thread pool. If a client calls /hello, immediately followed by another client that also calls /hello, wouldn’t the second client be blocked since the Tomcat I/O thread is hanging waiting for the response of the network call for the first client?
I am from an event-driven language where, in the same situation, the thread would serve the second request as well while waiting for the completion of the first request.
Please let me know where my understanding went wrong