是用户需要手工的把已处理的SelectionKey,从集合中移除。
public class ClientStub implements Runnable {
private Selector selector = null;
private SocketChannel channel = null;
private boolean started = false;
…
public void run() {
started = true;
try {
selector = Selector.open();
Selector sel = Selector.open();
channel = SocketChannel.open();
channel.configureBlocking(false);
channel.register(selector, SelectionKey.OP_READ
| SelectionKey.OP_CONNECT);
channel.connect(addr);
Set<SelectionKey> sks = null;
int keys = 0;
while (started) {
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



