11. Java IO NIO

Source: Internet
Author: User

There are many kinds of Java IO methods, which can be easily distinguished based on different IO abstract models and interaction modes.

The traditional java.io package , which is based on the flow model , provides some of the IO features we know best, such as File abstraction, input-output stream, and so on. The interaction mode is synchronous, blocking, that is, when reading the input stream or writing to the output stream, the thread will block there until the read and write actions are complete, and the calls between them are reliable linear order . The advantage of the java.io package is that the code is simple and intuitive, and the disadvantage is that IO efficiency and extensibility have limitations, which can easily become the bottleneck of application performance. In many cases, people also classify some of the network APIs provided below java.net, such as sockets, ServerSocket, and HttpURLConnection, into the synchronous blocking IO class library because network traffic is also an IO behavior.

The NIO Framework (Java.nio package), introduced in JDK 1.4, provides new abstractions such as Channel,Selector, andBuffer , which can be used to build multiplexed , Synchronizes non-blocking IO programs while providing high-performance data operations closer to the underlying operating system.

In Java 7, NIO has been further improved, that is, NiO 2, which introduces asynchronous nonblocking io , and many people call it AIO(asynchronous IO). asynchronous IO operations are based on the event and callback mechanism , which can be understood simply as the application operation is returned directly without blocking it, and when background processing is complete, the operating system notifies the appropriate thread to follow up.

From traditional IO (BIO) to NiO,NiO 2 (AIO), there are many areas where you can expand and examine points, such as:

    • Basic API functions and differences between design, Inputstream/outputstream and Reader/writer.

    • The basic composition of NiO and NiO 2.

    • Given the scenario, we use different models to analyze the design and implementation principles of BIO, NIO and other models.

    • How does NIO provide high-performance data manipulation based on how it works?

    • Or, from a developer's point of view, what do you think is the problem with NIO's own implementation? Do you have any ideas for improvement?

11. Java IO NIO

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.