上篇文章说的java的异步IO,熟悉unix IO调度方式的朋友应该清楚unix操作系统在非阻塞的调用形式结合selectors(选择器)select系统调用(感兴趣的朋友可以看看steven unix高级系统编程或者unix网络编程相当经典)提供了IO多路复用调用,这也是高并发服务器的IO调用方式(现在最新linux内核也提供了epoll形式的非阻塞调用这个留在以后讨论)。
以下就是nonblocking的socket
SocketChannel sc = SocketChannel.open();
sc.configureBlocking (false);// nonblocking
...
if ( ! sc.isBlocking()) {
doSomething (cs);
}
下面介绍选择器
我们上面提到到的SocketChannel继承了SelectableChannel接口,也就是说SocketChannel是可选择的,selectors可以理解为它提供询问操作系统内核Socket是否准备好进行I/O操作的能力,如果已经准备好他就返回准备好的SocketChannel列表。当然这要求有大量的SocketChannel已经与selectors关联上,也就是SocketChannel已经注册到selectors。
For example, a SocketChannel object
could be asked if it has any bytes ready to read, or we may want to know if a
ServerSocketChannel has any incoming connections ready to accept.
The Selector, SelectableChannel, and SelectionKey Classes
Selector
The Selector class manages information about a set of registered channels and
their readiness states. Channels are registered with selectors, and a selector can be
asked to update the readiness states of the channels currently registered with it.
public abstract class Selector
{
public static Selector open() throws IOException
public abstract boolean isOpen();
public abstract void close() throws IOException;
public abstract SelectionProvider provider();
public abstract int select() throws IOException;
public abstract int select (long timeout) throws IOException;
public abstract int selectNow() throws IOException;
public abstract void wakeup();
public abstract Set keys();
public abstract Set selectedKeys();
}
SelectableChannel
All the socket channel classes are selectable,
as well as the channels obtained from a Pipe object. SelectableChannel objects
can be registered with Selector objects, along with an indication of which
operations on that channel are of interest for that selector. A channel can be
registered with multiple selectors, but only once per selector.
SelectionKey
A SelectionKey encapsulates the registration relationship between a specific
channel and a specific selector. A SelectionKey object is returned from
SelectableChannel.register() and serves as a token representing the registration.
SelectionKey objects contain two bit sets (encoded as integers) indicating which
channel operations the registrant has an interest in and which operations the
channel is ready to perform.
public abstract class SelectionKey
{
public static final int OP_READ
public static final int OP_WRITE
public static final int OP_CONNECT
public static final int OP_ACCEPT
public abstract SelectableChannel channel();
public abstract Selector selector();
public abstract void cancel();
public abstract boolean isValid();
public abstract int interestOps();
public abstract void interestOps (int ops);
public abstract int readyOps();
public final boolean isReadable()
public final boolean isWritable()
public final boolean isConnectable()
public final boolean isAcceptable()
public final Object attach (Object ob)
public final Object attachment()
}
这篇将了几个关于多路复用IO类的概念,下篇文章从实例讲解多路复用IO类的使用。
注:以上定义描述来自Oreilly java NIO
分享到:
相关推荐
MC8051 IP Core Key Features ...- No multiplexed I/O ports - 256 bytes internal RAM - Up to 64 kbyte ROM, up to 64 kbyte RAM - Source code available free of charge under the GNU LGPL license
Uinx,Window,Linux,DOS,Micintosh... 企业级用户需求:安全、稳定、高效 telnet 172.16.0.210 briup briup 1965,AT&T BL, GE, MIT MULTICS(MULTiplexed Information and Computing System) ...3)I/O 4)BUS
· 16-Bit 30 MSPS A/D converter · 3 .3V digital I/O compatibility · Guaranteed won¢t miss codes · 3-Channel operation up to 30 MSPS · 1~5.85x programmable gain · 2-Channel (even-odd) operation ...
xSocket-multiplexed-2.1.5-sources.jarxSocket-multiplexed-2.1.5-sources.jarxSocket-multiplexed-2.1.5-sources.jarxSocket-multiplexed-2.1.5-sources.jarxSocket-multiplexed-2.1.5-sources.jarxSocket-...
• Ultra-low-voltage core and I/O power supplies • Frequency range – 933–10 MHz (data rate range: 1866–20 Mb/s/pin) • 8n prefetch DDR architecture • 8 internal banks for concurrent operation • ...
Micron NAND Flash devices include an asynchronous data interface for high-performance I/O operations. These devices use a highly multiplexed 8-bit bus (I/Ox) to transfer commands, address, and data. ...
AD9388A 英文版手册,方便大家来使用AD9388A;该手册是10-bit integrated Multiformat, HDTV video decoder ,RGB Graphics Digitizer, and 2:1 Multiplexed HDMI/DVI Interface
Time-Multiplexed Online Checking
Synchronous design allows precise cycle control with the use of system clock I/O transactions are possible on every clock cycle. Range of operating frequencies, programmable burst length and ...
Frequency-Domain Channel Estimation for Polarization-Division-Multiplexed CO-OFDM/OQAM Systems
- 256Mbit (x16 device) = 4M x 4Bank x 16 I/O ● ●● ●DATA STROBE - x16 device: LDQS and UDQS - Bidirectional, data strobe (DQS) is transmitted and re- ceived with data, to be used in capturing ...
An authoritative yet highly accessible guide to the design andoperation of the FlexRay bus, the latest protocol for automotivenetwork communications A translation of the French edition, originally ...
UNIX practice for handling multiplexed I/O2. The idiom’s programmability was proved sapient astride a decade’s architectures and operating systems, as libevent [19], libev, Java NIO and others ...
How to Build a Scalable Multiplexed Server With NIO 文中讲述如何使用java nio来实现高性能的服务器。 1、建立高性能服务器遇到问题? 2、java nio 和 reactor 的映射关系 3、如果使用java nio 来实现高性能...
操作系统、外壳、GUI、图形用户界面、内核模式、主管模式、用户模式、I/O、输入/输出 1.1 什么是操作系统? 1.1.1 作为扩展机器的操作系统 架构, SATA, 串行 ATA, 磁盘驱动程序 “在这本书中,我们将谈论很多抽象。...
Time-Multiplexed Coded Aperture Imaging Learned Coded Aperture and Pixel Exposures for Compressive Imaging Systems
- Multiplexed Address/ Data - Pinout compatibility for all densities SUPPLY VOLTAGE - 3.3V device: VCC = 2.7 to 3.6V : HY27USXX121A - 1.8V device: VCC = 1.7 to 1.95V : HY27SSXX121A Memory Cell Array...
视频芯片NVP6124B资料(包括芯片手册及hisi驱动程序). NVP6124B include 4-Channels AHD2.0 RX and 9-Channels Audio Codec. It is sure that ...27/36/37.125/54/72/74.25/108/144/148.5/297MHz multiplexed.
Hybrid wavelength- and frequency-division multiplexed fiber laser sensor array
We design and demonstrate a type of multiplexed hologram by nanoscatterers inside a dielectric-loaded plasmonic waveguide with guided-wave illuminations. The mode division multiplexed hologram (MDMH) ...