IoProvider: providing registration and cancellation of registration for all channel
SocketChannel want to read data from, but it requires the use of asynchronous manner, the need by the observer mode, take registration and deregistration way.
When the data is readable or SocketChanne Preferably, the processing performed by the callback Callback
IoArgs: encapsulation of IO, input parameters
Receiver: receives data
Sender: send data
Connector: representative of a connection, the package and Reciver Sender
IoContext: create a single example, can be acquired only IoProvider
SocketChannelAdapter: receiving asynchronous, asynchronous transmit and closing operation of the specific implementation.
Class Diagram:
Server thread icon:
operation result:
Connecting the client 10, and sends data
Only four threads received on the server in optimization (Input-Thread -1 / -2 / -3 / -4), pool-n-thread-1 is forwarded thread, there is no optimization
二、NIO vs IO
IO: a flow-oriented, blocking IO
(Stream oriented、Blocking IO)
NIO: oriented in the buffer, nonblocking IO, Selector Selector
(Buffer oriented、Non blocking IO、 Selectors)
Third, blocking IO thread processing data
To read the next piece of data if just one thread, then when will block after it reads the data, it can only read data is completed.
It is a piece of data down the execution, it is a serial process
Four, NIO thread processing data
First registered in the Channel Selector in
In the thread, begin to read the data, it will be read into the Channel, the Channel will fill data into the Buffer. Then checked and processed piece of data. Immediately followed by the next data is read.
It is also a serial process, but it is only when there is data in the Channel will execute this process, when there is no data, not the subsequent process, thus avoiding the blocking of the data.
Fives,
Receiving by a client linked to accept SeverSocket, each link may be used a single thread, a thread pool may be used comprising four or more threads to complete. Write operation can also be done by the thread pool.
six,
All links can be done by reading and writing of a thread process, read, write, execute separately
Seven,
The relationship between lower thread blocking IO mode:
NIO client receiving services under way:
NIO server to receive under the thread adjustment: