The NIO Foundation in Java

Source: Internet
Author: User

In jdk1.4, a new package was added, java.nio.*, which introduced the new JAVAI/O library to speed up, and in fact, the old I/O package was re-implemented using NIO.

What does this n in relation to Io,nio mean? "Java programming thought" called the small title "New I/O", the other is the first letter of Non-blocking, anyway, NiO is indeed a new processing non-blocking IO.

Several core components of NIO: Chennels (channel), buffers (cache), selectors (selector).

We can think of the channel as a large tank filled with water, while the cache (buffer) is a bucket, the bucket can be filled with water to be transported to another place, we do not have direct contact with the tank, are directly through the bucket (Buffer) interaction. In order to transport more water faster, we can use multiple buckets, and we can choose (Selector) which buckets how to fill the water, of course, we can not only from the tank through the bucket water can also be sent to the water tank.

The main channel implementations in Java are:

FileChannel: For file io, you can get the file channel through the Fileinputstream,fileoutputstream,randomaccessfile object's Getchannel ().
Datagramchannel: is a channel that can send and receive UDP packets. Use Datagramchannel.open () to open the channel.
Socketchannel: is a channel that is connected to a TCP network socket. Get using Socketchannel.open ().
Serversocketchannel: is a selectable channel for stream-oriented listening sockets, obtained using Serversocketchannel.open ().

The NIO Foundation in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.