Java NIO Model (i)

Source: Internet
Author: User

1. Blocking I/O communication model

1. Performance: A connection to a single-thread model results in a significant limit on the number of concurrent accesses and system throughput on the server

2. Reliability: Due to the synchronous blocking mode of IO operation, when the network congestion or slow logical processing causes the IO thread to be suspended, the blocking time is unpredictable

3. Maintainability: The number of IO threads cannot be effectively controlled, resources cannot be effectively shared (multithreading concurrency problem), System maintainability is poor

2. Asynchronous, non-blocking, event-driven NIO framework 3.selector function 4. Three Concepts

multiplexed, non-blocking I/O, which is much more scalable than thread-oriented, blocking I/O, is provided by selector S, selectable channels,

and selection keys.

A selector is a multiplexor of selectable channels, which in turn was a special type of channel that can Be put into non-blocking mode.

To perform multiplexed I/O operations, one or more selectable channels is first created, put into non-blocking mode, and registered with

A selector.  Registering a channel specifies the set of I/O operations that'll be tested for readiness by the selector, and returns a selection

Key that represents the registration.

Once some channels has been registered with a selector, a selection operation can is performed in order To discover which channels, if

Any, with become ready to perform one or more of the operations in which interest is previously declared. If A channel is ready then the

Key returned when it is registered is added to the selector ' s selected-key set. The key set, and the keys within it, can be examined

In order to determine the operations for which all channel is ready. From each key one can retrieve the corresponding channel in order to

Perform whatever I/O operations is required.

That a selection key indicates the IT channel is the ready for some operation are a hint, but not a guarantee, that Such an operation can is

Performed by a thread without causing the thread to block. It is imperative this code that performs multiplexed I/O be written so as to

Ignore these hints when they prove to be incorrect.

5. Thread Safety

Selection keys is safe for use by multiple concurrent threads. The operations of reading and writing the interest set would, in general, be

Synchronized with certain operations of the selector. Exactly how this synchronization are performed is implementation-dependent:

In a naive implementation, reading or writing the interest set could block indefinitely if a selection operation is already In progress;

In a high-performance implementation, reading or writing the interest set may block briefly, if at all.

In any case, a selection operation would always use the Interest-set value that is current at the moment that the Operatio N began.

Java NIO Model (i)

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.