- 浏览: 1130824 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (411)
- Java Foundation (41)
- AI/机器学习/数据挖掘/模式识别/自然语言处理/信息检索 (2)
- 云计算/NoSQL/数据分析 (11)
- Linux (13)
- Open Source (12)
- J2EE (52)
- Data Structures (4)
- other (10)
- Dev Error (41)
- Ajax/JS/JSP/HTML5 (47)
- Oracle (68)
- FLEX (19)
- Tools (19)
- 设计模式 (4)
- Database (12)
- SQL Server (9)
- 例子程序 (4)
- mysql (2)
- Web Services (4)
- 面试 (8)
- 嵌入式/移动开发 (18)
- 软件工程/UML (15)
- C/C++ (7)
- 架构Architecture/分布式Distributed (1)
最新评论
-
a535114641:
LZ你好, 用了这个方法后子页面里的JS方法就全不能用了呀
页面局部刷新的两种方式:form+iframe 和 ajax -
di1984HIT:
学习了,真不错,做个记号啊
Machine Learning -
赵师傅临死前:
我一台老机器,myeclipse9 + FB3.5 可以正常使 ...
myeclipse 10 安装 flash builder 4.6 -
Wu_Jiang:
触发时间在将来的某个时间 但是第一次触发的时间超出了失效时间, ...
Based on configured schedule, the given trigger will never fire. -
cylove007:
找了好久,顶你
Editable Select 可编辑select
适用:
event and data-driven apps
selector(The Selector class plays the role of a Reactor in the Reactor pattern scenario.) reactor proactor
http://www.kegel.com/c10k.html
https://chamibuddhika.wordpress.com/2012/08/11/io-demystified/
Scalable Event Multiplexing: epoll vs. kqueue:
http://www.eecs.berkeley.edu/~sangjin/2012/12/21/epoll-vs-kqueue.html
non-blocking and asynchronous io 之间的区别到底是什么?
https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014882947
http://doc.akka.io/docs/akka/2.3.8/general/terminology.html
http://stackoverflow.com/questions/3867042/one-thread-per-client-doable?lq=1
http://stackoverflow.com/questions/592303/asynchronous-io-in-java
Scalable IO in Java:
http://gee.cs.oswego.edu/dl/cpjslides/nio.pdf
Reactor Pattern Explained - Part 1:(part 2 / 3 等见链接)
http://jeewanthad.blogspot.com/2013/02/reactor-pattern-explained-part-1.html
Reactor和Proactor模式比较
http://liuxun.org/blog/reactor-he-proactor-mo-shi-bi-jiao/
Reactor: http://daimojingdeyu.iteye.com/blog/828696
待整理:何谓 IO? 及 Synchronous I/O vs Asynchronous I/O(Blocking I/O vs Non-Blocking I/O):
http://xcybercloud.blogspot.com/2009/06/network-io-blockingnon-blocking-vs.html
http://www.ibm.com/developerworks/library/j-nio2-1/
http://blog.csdn.net/historyasamirror/article/details/5778378
http://www.artima.com/articles/io_design_patterns2.html
http://www.cppblog.com/pansunyou/archive/2012/12/06/139343.html
http://www.developer.com/java/article.php/10922_3837316_3/Non-Blocking-IO-Made-Possible-in-Java.htm
http://stackoverflow.com/questions/5529137/java-non-blocking-and-asynchronous-io-with-nio-nio-2-jsr203-reactor-proact
http://stackoverflow.com/questions/2625493/asynchronous-vs-non-blocking?rq=1
http://www.cnblogs.com/zhuYears/archive/2012/09/28/2690194.html
http://tutorials.jenkov.com/java-nio/buffers.html#flip
http://blog.csdn.net/wuxianglong/article/details/6604817
http://docs.oracle.com/javase/1.4.2/docs/guide/nio/
http://stackoverflow.com/questions/1455117/best-model-for-an-nio-implementation
http://www.daniweb.com/software-development/computer-science/threads/384575/synchronous-vs-asynchronous-blocking-vs-non-blocking
http://stackoverflow.com/questions/8546273/is-non-blocking-i-o-really-faster-than-multi-threaded-blocking-i-o-how
Java™ I/O, NIO, and NIO.2:
http://docs.oracle.com/javase/7/docs/technotes/guides/io/
New I/O APIs:
http://docs.oracle.com/javase/1.4.2/docs/guide/nio/
Asynchronous I/O, or non-blocking I/O, is a form of input/output processing that permits other processing to continue before the transmission has finished.
核心概念: Channel 的 Multiplexed(多路复用):
A 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.
Selector 的 readiness selection:
Java NIO vs. IO:
https://blogs.oracle.com/slc/entry/javanio_vs_javaio
http://tutorials.jenkov.com/java-nio/nio-vs-io.html
NIO Performance Improvement compared to traditional IO in Java:
http://stackoverflow.com/questions/7611152/nio-performance-improvement-compared-to-traditional-io-in-java
event and data-driven apps
selector(The Selector class plays the role of a Reactor in the Reactor pattern scenario.) reactor proactor
http://www.kegel.com/c10k.html
引用
level-triggered & edge-triggered 中断:
http://stackoverflow.com/questions/1966863/level-vs-edge-trigger-network-event-mechanisms
http://venkateshabbarapu.blogspot.com/2013/03/edge-triggered-vs-level-triggered.html
level:在某个持续的状态下,会一直被触发
edge:事件发生的时候被触发,且处理事件期间不会被重复触发
completion notification VS readiness notification(notification 即 event notification):
http://stackoverflow.com/questions/1966863/level-vs-edge-trigger-network-event-mechanisms
http://venkateshabbarapu.blogspot.com/2013/03/edge-triggered-vs-level-triggered.html
level:在某个持续的状态下,会一直被触发
edge:事件发生的时候被触发,且处理事件期间不会被重复触发
completion notification VS readiness notification(notification 即 event notification):
https://chamibuddhika.wordpress.com/2012/08/11/io-demystified/
引用
The socket/file descriptors are abstracted
using Channels and Selector encapsulates the selection system call.
using Channels and Selector encapsulates the selection system call.
Scalable Event Multiplexing: epoll vs. kqueue:
http://www.eecs.berkeley.edu/~sangjin/2012/12/21/epoll-vs-kqueue.html
non-blocking and asynchronous io 之间的区别到底是什么?
https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014882947
http://doc.akka.io/docs/akka/2.3.8/general/terminology.html
http://stackoverflow.com/questions/3867042/one-thread-per-client-doable?lq=1
引用
The JVM for Linux is using one to one thread mapping. This means that every Java thread is mapped to one native OS thread.
So creating a thousand of threads or more is not a good idea because it will impact your performance (context switching, cache flushes / misses, synchronization latency etc). It also doesn't make any sense if you have less than a thousand of CPUs.
The only adequate solution for the serving many clients in parallel is to use asynchronous I/O. Please see this answer on Java NIO for details.
So creating a thousand of threads or more is not a good idea because it will impact your performance (context switching, cache flushes / misses, synchronization latency etc). It also doesn't make any sense if you have less than a thousand of CPUs.
The only adequate solution for the serving many clients in parallel is to use asynchronous I/O. Please see this answer on Java NIO for details.
http://stackoverflow.com/questions/592303/asynchronous-io-in-java
引用
Java's NIO package (as of Java6), provides support for non-blocking I/O only, via Selectors. Java7 is hopefully going to ship with NIO.2, which includes asynchronous I/O support.
Non-blocking IO the kernel calls don't block under buffer-full(on writes) and buffer-empty(on reads), these states result in soft-error returns from the respective APIs.However non-blocking IO still copies data between user-space and kernel-space causing an unwanted extra copying of data which has a significant overhead when a lot of data is involved.The kernel then(may)copy the data yet again into packet size pieces with networking protocol overhead around it.Some network stacks/hardware drivers may support scatter gather to optimize the in kernel stages,but worst case is 3 copies.
Async IO accepts to remove the extra copying action during the data transition between user-space and kernel-space.This allows the kernel to directly access the data from user-space.To achieve this the application prepares memory and posts an IO request to the kernel.Control returns back to the application (the API is much like non-blocking).At some future point in time the kernel may access the user-space memory while performing the IO.Once done the kernel fires a signal like callback into user-space via the completion handler to notify the application of the IO result of request.
From a programming basis, non-blocking io (based usually on select) means that you still have to identify which sockets have incomming data on them. Async IO results in you getting a callback (or event) telling you the results of the IO action. There is also less kernel work to do, in theory asnyc io done in the kernal allows higher throughput and/or lower latency
Non-blocking IO the kernel calls don't block under buffer-full(on writes) and buffer-empty(on reads), these states result in soft-error returns from the respective APIs.However non-blocking IO still copies data between user-space and kernel-space causing an unwanted extra copying of data which has a significant overhead when a lot of data is involved.The kernel then(may)copy the data yet again into packet size pieces with networking protocol overhead around it.Some network stacks/hardware drivers may support scatter gather to optimize the in kernel stages,but worst case is 3 copies.
Async IO accepts to remove the extra copying action during the data transition between user-space and kernel-space.This allows the kernel to directly access the data from user-space.To achieve this the application prepares memory and posts an IO request to the kernel.Control returns back to the application (the API is much like non-blocking).At some future point in time the kernel may access the user-space memory while performing the IO.Once done the kernel fires a signal like callback into user-space via the completion handler to notify the application of the IO result of request.
From a programming basis, non-blocking io (based usually on select) means that you still have to identify which sockets have incomming data on them. Async IO results in you getting a callback (or event) telling you the results of the IO action. There is also less kernel work to do, in theory asnyc io done in the kernal allows higher throughput and/or lower latency
Scalable IO in Java:
http://gee.cs.oswego.edu/dl/cpjslides/nio.pdf
Reactor Pattern Explained - Part 1:(part 2 / 3 等见链接)
http://jeewanthad.blogspot.com/2013/02/reactor-pattern-explained-part-1.html
Reactor和Proactor模式比较
http://liuxun.org/blog/reactor-he-proactor-mo-shi-bi-jiao/
Reactor: http://daimojingdeyu.iteye.com/blog/828696
待整理:何谓 IO? 及 Synchronous I/O vs Asynchronous I/O(Blocking I/O vs Non-Blocking I/O):
http://xcybercloud.blogspot.com/2009/06/network-io-blockingnon-blocking-vs.html
http://www.ibm.com/developerworks/library/j-nio2-1/
http://blog.csdn.net/historyasamirror/article/details/5778378
http://www.artima.com/articles/io_design_patterns2.html
http://www.cppblog.com/pansunyou/archive/2012/12/06/139343.html
http://www.developer.com/java/article.php/10922_3837316_3/Non-Blocking-IO-Made-Possible-in-Java.htm
http://stackoverflow.com/questions/5529137/java-non-blocking-and-asynchronous-io-with-nio-nio-2-jsr203-reactor-proact
http://stackoverflow.com/questions/2625493/asynchronous-vs-non-blocking?rq=1
http://www.cnblogs.com/zhuYears/archive/2012/09/28/2690194.html
http://tutorials.jenkov.com/java-nio/buffers.html#flip
http://blog.csdn.net/wuxianglong/article/details/6604817
http://docs.oracle.com/javase/1.4.2/docs/guide/nio/
http://stackoverflow.com/questions/1455117/best-model-for-an-nio-implementation
http://www.daniweb.com/software-development/computer-science/threads/384575/synchronous-vs-asynchronous-blocking-vs-non-blocking
http://stackoverflow.com/questions/8546273/is-non-blocking-i-o-really-faster-than-multi-threaded-blocking-i-o-how
引用
I/O includes multiple kind of operations like reading and writing data from hard drives, accessing network resources, calling web services or retrieving data from databases. Depending on the platform and on the kind of operation, asynchronous I/O will usually take advantage of any hardware or low level system support for performing the operation. This means that it will be performed with as little impact as possible on the CPU.
At application level, asynchronous I/O prevents threads from having to wait for I/O operations to complete. As soon as an asynchronous I/O operation is started, it releases the thread on which it was launched and a callback is registered. When the operation completes, the callback is queued for execution on the first available thread.
If the I/O operation is executed synchronously, it keeps its running thread doing nothing until the operation completes. The runtime doesn't know when the I/O operation completes, so it will periodically provide some CPU time to the waiting thread, CPU time that could have otherwise be used by other threads that have actual CPU bound operations to perform.
So, as @user1629468 mentioned, asynchronous I/O does not provide better performance but rather better scalability. This is obvious when running in contexts that have a limited number of threads available, like it is the case with web applications. Web application usually use a thread pool from which they assign threads to each request. If requests are blocked on long running I/O operations there is the risk of depleting the web pool and making the web application freeze or slow to respond.
One thing I have noticed is that asynchronous I/O isn't the best option when dealing with very fast I/O operations. In that case the benefit of not keeping a thread busy while waiting for the I/O operation to complete is not very important and the fact that the operation is started on one thread and it is completed on another adds an overhead to the overall execution.
At application level, asynchronous I/O prevents threads from having to wait for I/O operations to complete. As soon as an asynchronous I/O operation is started, it releases the thread on which it was launched and a callback is registered. When the operation completes, the callback is queued for execution on the first available thread.
If the I/O operation is executed synchronously, it keeps its running thread doing nothing until the operation completes. The runtime doesn't know when the I/O operation completes, so it will periodically provide some CPU time to the waiting thread, CPU time that could have otherwise be used by other threads that have actual CPU bound operations to perform.
So, as @user1629468 mentioned, asynchronous I/O does not provide better performance but rather better scalability. This is obvious when running in contexts that have a limited number of threads available, like it is the case with web applications. Web application usually use a thread pool from which they assign threads to each request. If requests are blocked on long running I/O operations there is the risk of depleting the web pool and making the web application freeze or slow to respond.
One thing I have noticed is that asynchronous I/O isn't the best option when dealing with very fast I/O operations. In that case the benefit of not keeping a thread busy while waiting for the I/O operation to complete is not very important and the fact that the operation is started on one thread and it is completed on another adds an overhead to the overall execution.
Java™ I/O, NIO, and NIO.2:
http://docs.oracle.com/javase/7/docs/technotes/guides/io/
IO
New I/O
New I/O APIs:
http://docs.oracle.com/javase/1.4.2/docs/guide/nio/
Asynchronous I/O, or non-blocking I/O, is a form of input/output processing that permits other processing to continue before the transmission has finished.
核心概念: Channel 的 Multiplexed(多路复用):
A 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.
Selector 的 readiness selection:
引用
readiness selection 是什么?举个例子,以 network programming 为例, readiness selection 指 the ability to choose a socket that will not block when read or written.
http://underpop.online.fr/j/java/java-network-programming/javanp3-CHP-12-SECT-5.html
http://underpop.online.fr/j/java/java-network-programming/javanp3-CHP-12-SECT-5.html
Java NIO vs. IO:
https://blogs.oracle.com/slc/entry/javanio_vs_javaio
http://tutorials.jenkov.com/java-nio/nio-vs-io.html
NIO Performance Improvement compared to traditional IO in Java:
http://stackoverflow.com/questions/7611152/nio-performance-improvement-compared-to-traditional-io-in-java
发表评论
-
J2SE Evolution
2013-04-11 15:39 1162Java 7 New Features Java SE 7 ... -
未完 java设计: naming convention | 命名规范
2012-11-20 16:45 2097应该遵循的规范: 类/接口/属性名,使用名词或形容词 ... -
未完 Java: enum 枚举
2012-11-19 20:29 1767http://stackoverflow.com/que ... -
Java多线程之 concurrent 并发包
2012-11-01 07:47 1959Java Tutorials -> Concur ... -
未完 Java Tips & Tricks & Notes
2012-09-12 10:00 1081Hidden Features of Java: h ... -
未完 Java Socket
2012-09-12 08:42 981Java SocketJava SocketJava Sock ... -
Java For-each Loop & Iterable | 增强型For循环和Iterable接口
2012-09-11 21:50 2007增强型For循环没什么好说的,Just see link ... -
未完 Java Collections | 容器
2012-09-06 11:35 1795Sources: http://docs.oracle.com ... -
Java object Initialization (class Instantiation) | 对象的初始化(即类的实例化)
2012-09-03 09:12 2950类实例即对象 ... -
未完Java class&interfac 's Loading, Linking and Initializing | 类与接口的加载、链接和初始化
2012-08-31 19:01 1621JVM装载一个类的时候,首先检查他有没有父类,如果有父类则装载 ... -
未完 java Static 总结
2012-08-31 18:47 1367static可以用来修饰: 字段 Fields 方法 Meth ... -
未完 JVM Runtime Data Areas & Java Memory Model | 内存分配模型 & Java数据存储
2012-08-31 18:43 1850Java虚拟机内存分配模型 需精读:Chapter 5 of ... -
Java Data Types & Literals | 数据类型 和 字面量
2012-08-30 18:12 3860Java数据类型划分: OR http:// ... -
未完 Variables 变量 (Instance/Class/Local)
2012-08-29 10:59 1647Local/Instance/Class Variables ... -
未完 Regular Expressions | 正则表达式
2011-08-25 11:43 1488Extended Regular Expression ... -
java Date(util.Date/sql.Date/sql.Timestamp/sql.Time) & Oracle DATE Type 时分秒 精度问题
2011-05-17 09:32 3894遇到的问题描述: 数据库为Oracle,其jdbc驱动为ojd ... -
Java byte code (bytecode)
2011-05-04 02:55 3843keys: bytecode, byte code, opco ... -
Java Classloading Mechanism : ClassLoader & ASM & 动态字节码增强
2011-04-21 13:29 2384Setting the class path: http:// ... -
class literal & instance.getClass() & Class.forName(String className)
2011-04-20 12:33 2294常用的几种取得Class类实例的方式: 1 class lit ... -
Java 数值计算
2011-04-20 02:44 2059java.lang.Math's floor(),ceil() ...
相关推荐
Java I/O学习笔记: 磁盘操作 字节操作 字符操作 对象操作 网络操作 NIO & AIO Java I/O Java是一种面向对象的编程语言,由Sun Microsystems于1995年推出。它是一种跨平台的语言,意味着可以在不同的操作系统上运行...
Java I/O, NIO, and NIO.2 is a power-packed book that accelerates your mastery of Java's various I/O APIs. In this book, you'll learn about classic I/O APIs (File, RandomAccessFile, the stream classes ...
【图解】深入分析Java I_O工作机制,从传统IO分析至NIO,调优以及原理,不可用于商业用途,如有版权问题,请联系删除!
java学习笔记1(java io/nio)设计模式
压缩包内只有一个文件,Java面试手册.pdf 目录: Java基础题 Java集合 异常&反射 IO&NIO 多线程 JVM Linux MySQL Spring Mybatis Nginx Redis Dubbo SpringBoot Kafka SpringCloud 简历
New I/O (NIO), and NIO.2 categories. You learn what each category offers in terms of its capabilities, and you also learn about concepts such as paths and Direct Memory Access. Chapters 2 through 5 ...
NULL 博文链接:https://haifeng0730.iteye.com/blog/1507931
1、Java IO_NIO 2、Java+IO.pdf
NULL 博文链接:https://zhangshixi.iteye.com/blog/683767
Many serious Java programmers, especially enterprise Java programmers, consider the new I/O API--called NIO for New Input/Output--the most important feature in the 1.4 version of the Java 2 Standard ...
这些新的I/O特性主要包含在java.nio软件包及其子包中,并被命名为New I/O(NIO)。通过本书,您将学会如何使用这些令人兴奋的新特性来极大地提升Java应用程序的I/O效率。 目录 前言 第一章 简介 第二章 缓冲...
java NIO是 java New IO 的简称,在 jdk1.4 里提供的新 api 。 Sun 官方标榜的特性如下: – 为所有的原始类型提供 (Buffer) 缓存支持。 – 字符集编码解码解决方案。 – Channel :一个新的原始 I/O 抽象。 – 支持...
Input/output (I/O) is not a sexy subject, but it’s an important part of non-trivial applications. This book introduces you to most of Java’s I/O capabilities as of Java 8 update 51.
java频道\java io 与java nio区别.txt
Java IO NIO and NIO 2 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn...
Java NIO 深入探讨了 1.4 版的 I/O 新特性,并告诉您如何使用这些特性来极大地提升您所写的 Java 代码的执行效率。这本小册子就程序员所面临的有代表性的 I/O 问题作了详尽阐述,并讲解了 如何才能充分利用新的 I/O ...
Java IO NIO and NIO 2 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
java.nio (NIO stands for non-blocking I/O) is a collection of Java programming language APIs that offer features for intensive I/O operations. It was introduced with the J2SE 1.4 release of Java by ...
本书介绍了 Java 平台上的高级输入/输出,具体点说,就是使用 Java 2 标准版(J2SE)软件 ...名为 New I/O(NIO)。通过本书,您将学会如何使用这些令人兴奋的新特性来极大地提升 Java 应 用程序的 I/O 效率。