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.

 

java NIO 模型(一)的更多相关文章

  1. Java NIO:浅析I/O模型

    也许很多朋友在学习NIO的时候都会感觉有点吃力,对里面的很多概念都感觉不是那么明朗.在进入Java NIO编程之前,我们今天先来讨论一些比较基础的知识:I/O模型.下面本文先从同步和异步的概念 说起, ...

  2. Java NIO 与 基于reactor设计模式的事件处理模型

    Java NIO非堵塞应用通常适用用在I/O读写等方面,我们知道,系统运行的性能瓶颈通常在I/O读写,包括对端口和文件的操作上,过去,在打开一个I/O通道后,read()将一直等待在端口一边读取字节内 ...

  3. Java NIO:浅析I/O模型(转)

    原文链接:http://www.cnblogs.com/dolphin0520/p/3916526.html 以下是本文的目录大纲: 一.什么是同步?什么是异步? 二.什么是阻塞?什么是非阻塞? 三. ...

  4. Java网络编程和NIO详解2:JAVA NIO一步步构建IO多路复用的请求模型

    Java网络编程与NIO详解2:JAVA NIO一步步构建IO多路复用的请求模型 知识点 nio 下 I/O 阻塞与非阻塞实现 SocketChannel 介绍 I/O 多路复用的原理 事件选择器与 ...

  5. Java NIO学习与记录(八): Reactor两种多线程模型的实现

    Reactor两种多线程模型的实现 注:本篇文章例子基于上一篇进行:Java NIO学习与记录(七): Reactor单线程模型的实现 紧接着上篇Reactor单线程模型的例子来,假设Handler的 ...

  6. Java NIO学习与记录(五): 操作系统的I/O模型

    操作系统的I/O模型 在开始介绍NIO Reactor模式之前,先来介绍下操作系统的五种I/O模型,了解了这些模型,对理解java nio会有不小的帮助. 先来看下一个服务端处理一次网络请求的流程图: ...

  7. Java NIO学习系列六:Java中的IO模型

    前文中我们总结了linux系统中的5中IO模型,并且着重介绍了其中的4种IO模型: 阻塞I/O(blocking IO) 非阻塞I/O(nonblocking IO) I/O多路复用(IO multi ...

  8. Java网络编程与NIO详解2:JAVA NIO 一步步构建I/O多路复用的请求模型

    微信公众号[黄小斜]作者是蚂蚁金服 JAVA 工程师,专注于 JAVA 后端技术栈:SpringBoot.SSM全家桶.MySQL.分布式.中间件.微服务,同时也懂点投资理财,坚持学习和写作,相信终身 ...

  9. Java NIO之理解I/O模型

    前言 自己以前在Java NIO这块儿,一直都是比较薄弱的,以前还因为这点知识而错失了一个机会.所以最近打算好好学习一下这部分内容,我想应该也会有朋友像我一样,一直想闹明白这块儿内容.但是一直无从下手 ...

随机推荐

  1. SpringCloud系列七:使用Ribbon实现客户端侧负载均衡

    1. 回顾 在前面,已经实现了微服务的注册与发现.启动各个微服务时,Eureka Client会把自己的网络信息注册到Eureka Server上. 但是,在生成环境中,各个微服务都会部署多个实例,因 ...

  2. vs2017 生成代码策略 旧的 ObjectContext

    新版本的VS中已经去掉了生成ObjectContext的功能,需要手动下载一个生成ObjectContext的T4模板.在模型设计器的上下文菜单中选择添加代码生成项,在联机模板中选择对应EF版本的Ob ...

  3. 【SSH三大框架】Hibernate基础第九篇:cascade关联关系的级联操作

    这里要说的是Hibernate的关联关系的级联操作,使用cascade属性控制. 依旧用部门和员工举例.多个员工相应一个部门(多对一关联关系) 员工类:Employee.java package cn ...

  4. 基于Python3 + OpenCV3.3.1的远程监控程序

    基于Python3 + OpenCV3.3.1的远程监控程序 一.环境配置 OpenCV是一个基于(开源)发行的跨平台计算机视觉库,利用OpenCV能够实现视频图像的捕获. 关于python3中Ope ...

  5. spring reactor记录操作日志

    1.注册日志的类: @Configuration@EnableReactorpublic class ReactorConfig { /** * * 〈注册审计日志 Reactor〉 */ @Bean ...

  6. TCP/IP笔记(一)网络基础知识

    计算机与网络发展 计算机自诞生伊始,经历了一系列演变与发展.大型通用机计算机.超级计算机.小型机.个人电脑.工作站.便携式电以及现如今的智能手机终端都是这一过程的产物.它们性能逐年增强,价格却逐年下降 ...

  7. PHP 关掉浏览器还会执行代码

    ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去 $int ...

  8. ubuntu 中wget (下载)命令用法

    Linux wget是一个下载文件的工具,它用在命令行下. 对于Linux用户是必不可少的工具,尤其对于网络管理员,经常要下载一些软件或从远程服务器恢复备份到本地服务器 1.使用wget下载单个文件 ...

  9. ChemDraw 15支持哪些输入格式

    当我们想让我们的化学图形应用在试卷编辑.论文撰写.刊物出版等各个方面,这个时候往往都得使用ChemDraw 15.它可以与很多第三方应用灵活.本ChemDraw教程介绍新版ChemDraw Profe ...

  10. Redis 在windows中启动

    redis-server.exe redis.windows.conf 或 redis-server.exe redis.conf