Detailed differences between Java NiO and Io (popular article)

Source: Internet
Author: User

The detailed differences between Java NiO and Io (popular article)--Reprint

As far as speed is concernedCPU > 内存 > 硬盘

    • I-From hard disk to memory
    • O-From memory to hard drive

The first way : I read the data from the hard disk, then the program has been waiting, the data after reading, continue to operate. This approach is the simplest, called blocking IO.

The second way: I read the data from the hard disk, and then the program continues to execute, and so on after the data read, notify the current program (for the hardware called interrupts , called callbacks to the program),

The program can then process the data immediately, or it can perform the current operation to read the data.

When the program reads data from the hard disk into memory, the operating system uses 2 "tricks" to improve performance, that is, pre-reading , if I read the contents of the third track in the first sector,

Then you will probably also use the contents of the second track and the fourth track, so the operating system will read the contents of the nearby tracks in advance and put them in memory, which is the cache .

(PS: The above process is simplified)

As can be seen above, the operating system is block blocks from the hard drive to take data, like a large basin, suddenly put into a basin of water.

However, when Java is used, the old IO is actually based on the stream stream, that is, although the operating system gave me a basin of water, but I have to drink slowly with a straw.

Detailed differences between Java NiO and Io (popular article)

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.