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