Java NIO2

DatagramChannel If you want to receive datagrams at a certain local port number you have to bind to that local port number. If you only want to receive from a certain remote address/port number you can connect to that remote address/port. If you want to receive from anybody, don't connect. But you always have to bind to the local port the remotes are sending to.

 

note that all asynchronous channels initiate I/O operations (does not block the application toperform other tasks) and provide notifications when I/O completes. This rule is the foundation ofasynchronous channels, and from it derives the entire asynchronous channel API.
To begin our discussion of the asynchronous I/O big picture, we’ll look at forms. All asynchronous
I/O operations have one of two forms:
• Pending result
• Complete result

 

在高性能的I/O设计中,有两个比较著名的模式Reactor和Proactor模式,其中Reactor模式用于同步I/O,而Proactor运用于异步I/O操作。

在比较这两个模式之前,我们首先的搞明白几个概念,什么是阻塞和非阻塞,什么是同步和异步,同步和异步是针对应用程序和内核的交互而言的,同步指的是用户进程触发IO操作并等待或者轮询的去查看IO操作是否就绪,而异步是指用户进程触发IO操作以后便开始做自己的事情,而当IO操作已经完成的时候会得到IO完成的通知(异步的特点就是通知)。
而阻塞和非阻塞是针对于进程在访问数据的时候,根据IO操作的就绪状态来采取的不同方式,说白了是一种读取或者写入操作函数的实现方式,阻塞方式下读取或者写入函数将一直等待,而非阻塞方式下,读取或者写入函数会立即返回一个状态值。


http://liuxun.org/blog/reactor-he-proactor-mo-shi-bi-jiao/

posted on 2014-05-06 16:39  ukouryou  阅读(179)  评论(0编辑  收藏  举报

导航