Selector
创建
Selector selector = Selector.open();注册
// channel设置为非阻塞
channel.configureBlocking(false);
//channel根据感兴趣的状态,注册到selector
SelectionKey key = channel.register(selector, Selectionkey.OP_READ | SelectionKey.OP_WRITE); 就绪的channel
// 阻塞到至少有一个通道在你注册的事件上就绪了
int select();
// 和select()一样,除了最长会阻塞timeout毫秒
int select(long timeout);
// 不会阻塞,不管什么通道就绪都立刻返回
int selectNow();SelectionKey
例子
Last updated