Mads Nielsen
Mads Nielsen

Reputation: 644

Why is "Multiplexed, non-blocking I/O, [..] much more scalable than thread-oriented, blocking I/O"?

I'm reading about Channels in the JDK 7 docs (here), and stumbled upon this:

Multiplexed, non-blocking I/O, which is much more scalable than thread-oriented, blocking I/O, [...]

Is there a simple explanation as to why this is so?

Upvotes: 12

Views: 2030

Answers (2)

Louis Wasserman
Louis Wasserman

Reputation: 198033

"Blocking" means that threads have to wait as long as necessary for a resource to become available...which means, by definition, threads will be sitting around waiting for resources. Non-blocking avoids this sort of thing.

Generally, non-blocking solutions are trickier, but they avoid resource contention, which makes it much easier to scale up. (That said, the point of Channel is to make this less tricky.)

Upvotes: 3

Ben Voigt
Ben Voigt

Reputation: 283624

Because a thread stack is usually much larger than the data structure needed to support an async I/O connection. Also, scheduling thousands of threads is inefficient.

Upvotes: 6

Related Questions