The Io linux kernel will treat all external devices as a single file, and read and write to a file invokes the kernel system command, putting back a filename descriptor ( File descriptor), the read-write to a socket will also have a corresponding descriptor, called socketfd java NiO core class library Multiplexer selector is based on Epoll multiplexing technology implementation  I/O multiplexing technology enables multiple client requests to be processed simultaneously in a single-threaded scenario by reusing multiple I/O blocking to the same select block, which allows the system to process more than one request at a time epoll and select are similar in principle and make a lot of significant improvements 1 support a process open socket descriptor (FD) Unrestricted ( Only the maximum number of file handles is limited to the operating system), 1GB memory on the machine is about 100,000 handles, specific values can be viewed through Cat/proc/sys/fs/file-max 2 i/o Efficiency does not decrease linearly with the number of FD, the maintenance cost of the socket set, Epoll only operates on the active socket, because in the kernel implementation, Epoll is based on each FD above the callback function to achieve the amount, only the active socket will be active call callback function  3 use mmap to accelerate the kernel and user space message delivery, Epoll is implemented through the kernel and user space mmap the same piece of memory jdk1.7 Upgrade the original NiO class 1 provide the API to get the file attributes in bulk, These APIs are platform agnostic and also provide the SPI for standard file systems for each service provider's extended implementation  2 to provide AIO functionality, support for file-based asynchronous I/O operations, and asynchronous operations for network sockets 3 completed the defined channel functions, including the configurationand multicast datagram support synchronous blocking I/O, blocking time depends on the processing speed of the other I/O thread and the transmission speed of network I/O pseudo-asynchronous I/O Using a thread pool and task queue can implement an I/O communication framework called pseudo-async flaw, which is blocked when reading from the socket's input stream , until the following three things happen: 1 have data readable 2 available data has been read 3 a null pointer or I/O exception Pseudo-asynchronous I/O is actually just a simple optimization of the previous I/O threading model, unable to fundamentally resolve the synchronization i/ O resulting communication blocking issues nio (non-block I/O) In contrast to the socket class and the ServerSocket class, NiO also offers two different socket channel implementations for Socketchannel and Serversocketchannel, both of which support both blocking and non-blocking modes nio makes up for the lack of the original synchronous blocking I/O and provides a high-speed, block-oriented i/o buffer (buffer) object in the NIO class library in standard Java code, reflecting the new library and the original i/ An important difference of O, buffer is not only an array, but also provides structured access to data and maintenance of read-write location information Each Java base type (except the Boolean type) should have a buffer, most standard i/ O operations are used bytebuffer channel is a channel, the difference between the channel and the flow is that the channel is bidirectional, the flow is only moving in one direction, and the channel can be used for reading, writing, or both at the same time, Channel is full-duplex, UNIX underlying operating system channels are full-duplex, so it can better map the underlying operating system api The channel is divided into two main categories: Selectablechannel for network reading and writing and filechannel &NB for file operationsSP; multiplexer selector Multiplexer provides the ability to select a task that is already in place, and selector continuously polls the channel on which it is registered, if a read or write event occurs above a channel, The channel is in a ready state, is polled by the selector, and then gets the set of ready channel through Selectionkey for subsequent I/O operations, since the JDK uses epoll instead of the traditional select implementation, So it doesn't have the maximum connection handle 1024/2048 limit AIO nio 2.0 introduces the concept of a new asynchronous channel and provides an implementation of asynchronous file channels and asynchronous socket channels, The asynchronous channel provides the following two ways to get operation results  1 through the Java.util.concurrent.Future class to represent the result of an asynchronous operation  2 When performing an asynchronous operation, it is possible to implement asynchronous read-write by passing a java.nio.channels that does not require a multiplexer to poll the registered channel: NETTYTCP Sticky pack unpacking using Linebasedframedecoder and Stringdecoder can solve the read half-packet problem caused by the TCP sticky packet, The combination of the two is a text decoder that switches by line Delimiterbasedframedecoder automatically completes the decoding of messages with a delimiter-ending flag Fixedlengthframedecoder can automatically decode the fixed-length message Codec technology The default serialization mechanism for the JDK allows programmers to avoid manipulating the underlying byte arrays, primarily for network transport and object persistence when making cross-process service calls The transmitted Java object needs to be encoded as a byte array or an Bytebuffer object, and when the remote service reads to the Bytebuffer object or byte array, it needs to decode its into the Java object when it is sent, which is called the Java Object codec technology. Java serialization is only a of Java codec technology the binary array size encoded by the JDK serialization mechanism is 5 times times more than the binary encoding The advantages of the codec framework are often considered in the following ways:Whether to support cross-language, encoded stream size, codec performance, class library is small and easy to use protocol stack development is based on the existing basic protocol (eg HTTP protocol) encapsulation extended WebSocket Protocol development of the drawbacks of the HTTP protocol half-duplex protocol, In the client and server two direction transmission, but not at the same time transmission; The message adopts text transmission, lengthy and tedious; long polling compared to a new polling technology is comet, using Ajax, although it can achieve two-way communication, but still need to make a request, and generally use a long connection, Would laugh. Consume bandwidth and resources  HTML5 defines the WebSocket protocol to better conserve server resources and bandwidth and achieve real-time communication
IO NIO AIO notes for Java