axclientsocketpool.java

来自「java NIO源代码,初学者学习java NIO技术的基础代码」· Java 代码 · 共 32 行

JAVA
32
字号
package org.Arios.XServer;

import java.nio.channels.SelectionKey;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

public class AxClientSocketPool {
	protected CopyOnWriteArrayList<SelectionKey> clientList = new CopyOnWriteArrayList<SelectionKey>();
	protected static AxClientSocketPool instance = new AxClientSocketPool();;

	protected AxClientSocketPool() {
	}

	public static AxClientSocketPool getInstance() {
		return instance;
	}

	public void add(SelectionKey key) {
		if (!clientList.contains(key))
			clientList.add(key);
	}
	
	public void remove(SelectionKey key){
		if(clientList.contains(key))
			clientList.remove(key);
	}
	
	public Iterator<SelectionKey> getIterator(){
		return clientList.iterator();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?