zoukankan      html  css  js  c++  java
  • java NIO 模型(一)

    1. 阻塞I/O通信模型 

    1.性能:一连接一线程模型导致服务端的并发接入数和系统吞吐量受到极大限制

    2.可靠性:由于IO操作采用同步阻塞模式,当网络拥塞或者逻辑处理缓慢会导致IO线程被挂住,阻塞时间无法预测

    3.可维护性:IO线程数无法有效控制、资源无法有效共享(多线程并发问题),系统可维护性差

     
     
    2. 异步、非阻塞、基于事件驱动的NIO框架
     
     
     
     
    3.selector作用
     
    4.三个概念

    Multiplexed, non-blocking I/O, which is much more scalable than thread-oriented, blocking I/O, is provided by selectorsselectable channels,

    and selection keys.

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

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

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

    key that represents the registration.

    Once some channels have been registered with a selector, a selection operation can be performed in order to discover which channels, if

    any, have become ready to perform one or more of the operations in which interest was previously declared. If a channel is ready then the

    key returned when it was registered will be 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 each channel is ready. From each key one can retrieve the corresponding channel in order to

    perform whatever I/O operations are required.

    That a selection key indicates that its channel is ready for some operation is a hint, but not a guarantee, that such an operation can be

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

    ignore these hints when they prove to be incorrect.

    5.线程安全

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

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

    In a naive implementation, reading or writing the interest set may 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 will always use the interest-set value that was current at the moment that the operation began.

     
  • 相关阅读:
    SQL Server2008中删除重复记录
    Php环境在Windows (server 2003) 服务器部署标准 白丁简明版
    国外服务器鸟文windows,时间12小时制,如何改成24小时呢?我来告诉你
    将Capicom调用代码封装到ActiveX——解决javascript调Capicom读取数字证书信息时,IE弹出安全提示的问题
    Linq处理List数据
    C#将窗口最小化到系统托盘,并显示图标和快捷菜单
    C# 将程序添加到启动项 (写入注册表),及从启动项中删除
    C#中string[]数组和list<string>泛型的相互转换
    IIS7.5部署ASP.NET失败
    IIS 7.5版本中一些诡异问题的解决方案
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3947972.html
Copyright © 2011-2022 走看看