IO

同步:需要不断的轮询或者一次得到数据。

异步:不需要不断的轮询或者一次得到数据。

阻塞:调用的时候线程会阻塞。

非阻塞:调用的时候线程不会阻塞。

http://www.cnblogs.com/fanzhidongyzby/p/4098546.html

http://www.cnblogs.com/xuekyo/archive/2013/01/20/2868547.html

netty使用了几个selector,其中一个selector处于客户端的连接,多个seelctor用于处理读和写。其中每一个selector都是一个线程在跑。

netty并没有使用异步非阻塞的IO,使用的是selector,也就是异步的阻塞IO。

http://ifeve.com/netty-reactor-4/ 

下面的文章讲解了IO模型的使用

https://www.ibm.com/developerworks/cn/linux/l-async/

http://www.cnblogs.com/good-temper/p/5003892.html

http://tutorials.jenkov.com/java-nio/nio-vs-io.html

http://ifeve.com/java-nio-vs-io/

http://www.infoq.com/cn/articles/netty-high-performance

Channel

    1、FileChannel   FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下。

            我们无法直接打开一个FileChannel,需要通过使用一个InputStream、OutputStream或RandomAccessFile来获取一个FileChannel实例。 

          如:

RandomAccessFile aFile = new RandomAccessFile("data/nio-data.txt""rw");
2 FileChannel inChannel = aFile.getChannel();

   2、因为与Selector一起使用时,Channel必须处于非阻塞模式下。这意味着不能将FileChannel与Selector一起使用,因为FileChannel不能切换到非阻塞模式。而套接字通道都可以。

   3、

Channel的实现

这些是Java NIO中最重要的通道的实现:

    • FileChannel  (transtofm可以在通道之间进行数据传输)
    • DatagramChannel(UDP)
    • SocketChannel(TCP)

               ServerSocketChannel(监听TCP)          

 4、Pipe  pipe可以在多线程之间交换数据

5、URL可以打开一个connection。

http://ifeve.com/java-netword-url-urlconnection/

 

你可能感兴趣的:(IO)