Oi boa tarde. eu usei newFixedThreadPool, com valor 2, logo ao tentar executar 2 clientes, era para dar erro no terceiro, ele deveria esperar mas a execução seguiu lindamente como se fosse dinâmico... vou deixar meu código abaixo... ps:uso o intellij
server:
public class ServerTask {
public static void main(String[] args) throws IOException {
System.out.println("---STARTING SERVER---");
ServerSocket server = new ServerSocket(2548);
ExecutorService poolThreads = Executors.newFixedThreadPool(2);
while (true){
Socket socket = server.accept();
System.out.println("ACCEPTING NEW CUSTOMER AT THE DOOR:"+socket.getPort());
TaskDistributor distributor = new TaskDistributor(socket);
poolThreads.execute(distributor);
}
}
}
cliente:
public class ClientTask {
public static void main(String[] args) throws IOException {
Socket socket = new Socket("localhost",2548);
PrintStream exit = new PrintStream(socket.getOutputStream());
exit.println("c1");
System.out.println("Connection established");
Scanner scanner = new Scanner(System.in);
scanner.nextLine();
exit.close();
scanner.close();
socket.close();
}
}