/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package simpleserver; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.channels.*; /** * * @author Michael */ public class ConnectionListener extends Thread { private ServerSocketChannel socket = null; private RequestListener[] requestPool = new RequestListener[Main.POOL_SIZE]; private int nextListener = 0; public ConnectionListener() throws IOException { SocketAddress address = new InetSocketAddress(80); socket = ServerSocketChannel.open(); socket.socket().bind(address, 8); for (int index = requestPool.length; --index >= 0; ) requestPool[index] = new RequestListener(); start(); } public void run() { try { while (!Thread.interrupted()) { SocketChannel sc = socket.accept(); requestPool[nextListener = (nextListener + 1) % requestPool.length].add(sc); } } catch (IOException e) { throw new RuntimeException(e); } } }