Java NiO and IO

Source: Internet
Author: User

kernel space , user space , machine architecture , computer composition principle 、...... It's a bit esoteric.

My new book, Code puzzle, will have a special chapter on the relevant knowledge, and now write a short scientific text:

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, then the program continues to execute, and so on after the data read, notify the current program (for the hardware is called an interrupt , the program is called a callback ), and then the program can immediately process the data, you can also perform the current operation in reading data.

In the previous Java io, the nonblocking Io,nio introduced non-blocking IO.

Another is synchronous IO and asynchronous IO. Often said a term is "asynchronous non-blocking", as if asynchronous and non-blocking is the same thing, this is probably a misunderstanding it.

As for Java NIO's Selector, in the old Java IO system, it is stream-based, or "stream", streaming IO.

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 first sector of the third track content, then you will probably also use the second track and the fourth track content, So the operating system reads the contents of nearby tracks in advance and puts them in memory, which is the cache .

Java NiO and IO

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.