class NetworkServer extends InitialHandshake implements Runnable {
private final ServerSocket serverSocket;
private final ExecutorService pool;
public NetworkServer(int port, int poolSize) throws IOException {
serverSocket = new ServerSocket(port);
pool = Executors.newFixedThreadPool(poolSize);
}
public void run() {
try {
//Interdependent tasks
pool.submit(new SanitizeInput(password)); // password is defined in class InitialHandshake
pool.submit(new CustomHandshake(password)); // for e.g. client puzzles
pool.execute(new Handle(serverSocket.accept())); // handle connection
} catch (IOException ex) { pool.shutdown(); }
}
}
|