Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added NCCE/CS

...

Code Block
bgColor#FFCCCC
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(); }	 
  }
}

...

Code Block
bgColor#ccccff
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 {
      // Execute interdependent subtasks as a single combined task within this block
      pool.execute(new Handle(serverSocket.accept())); // handle connection
    } catch (IOException ex) { pool.shutdown(); }	 
  }
}

...