The NIO API was introduced in Java 1.4 and had since been used for wide number of applications. The NIO API covers IO non-blocking operations.
java.nio.* package contains following key constructs
- Buffers - Data Containers
- Chartsets - Containers translators for bytes and Unicode
- Channels - represents connections to entities capable of I/O operations
- Selectors - provide selectable, multiplexed non-blocking IO
- Regexps - provide provide some tools to manipulate regular expressions
We are mostly interested in the Channels, _ Selectors_ and Buffers parts in the MINA framework, except that we want to hide those elements to the user.
This user guide will thus focus on everything built on top of those internal components.
NIO vs BIO¶
It's important to understand the difference between those two APIs. BIO, or Blocking IO, relies on plain sockets used in a blocking mode : when you read, write or do whatever operation on a socket, the called operation will blcok the caller until the operation is completed.
In some cases, it's critical to be able to call the operation, and to expect the called operation to inform the caller when the operation is done : the caller can then do something else in the mean time.
This is also where NIO offers a better way to handle IO when you have numerous connected sockets : you dn't have to create a specific thread for each connection, you can just use a few threads to do the same job.
If you want to get more information about what covers NIO, there is a lot of good articles around the web, and a few books cobering this matter.