NIO non-blocking package for Android development (1)

Source: Internet
Author: User

 

The NiO non-blocking package series for Android development is reproduced at http://www.android123.com.cn/androidkaifa/695.html.

To improve the network communication performance of Android, we can use the high-performance NiO (New I/O) technology on Java for processing. Nio was introduced from JDK 1.4, we can understand the n of NiO as noblocking, which means non-blocking. It is blocking relative to traditional I/O methods, such as socket accpet () and read.

NIO mainly uses channel and selector for implementation. Java selector is similar to Winsock's select mode and is event-driven. The entire processing method uses the rotation state machine, if you have developed a Symbian application in the past, this method is a bit like an active object. The advantage is that a single thread saves system overhead and NiO can handle concurrency well, it is critical for Android online game development. using NiO for Multi-Point socket connections can greatly reduce thread usage and reduce the probability of thread deadlock. After all, mobile games have UI threads and music threads, network threads and management difficulties can be imagined. At the same time, low-speed devices such as I/O will affect the gaming experience.

NIO, as a medium-and high-load I/O model, has greatly improved compared with the traditional bio (blocking I/O), so there is no need for too many threads to process concurrency, saves the creation and destruction time. If too many threads are scheduled, and many threads may be idle, the CPU time is greatly wasted. At the same time, too many threads may be greatly reduced in performance, in general solutions, thread pools may be used to manage scheduling, but this method is not a permanent cure. Using NiO can greatly improve the concurrency efficiency. Of course, there are still some differences between NiO and AIO in JDK 7. AIO is updated. Of course, this is for Java. If you have developed a Winsock server, the I/O completion port such as iocp can solve more advanced loads. Of course, today android123 mainly explains why NiO is used in Android.

NiO is described in several types. As a feature of Java, we need to understand some new concepts, such as bytebuffer, channel, socketchannel, serversocketchannel, selector, and selectionkey. For specific usage, the android development network will be explained in detail tomorrow. Users can see java. NiO and Java. NiO. channels in the android SDK documentation.

Related 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.