add thread pool

This commit is contained in:
andrzej 2024-11-12 10:27:30 +01:00
parent d4572677f5
commit fda9f1d13b
3 changed files with 4 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,7 @@
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class Server { class Server {
public static void main(String[] args) { public static void main(String[] args) {
@ -14,7 +16,8 @@ class Server {
System.out.println("New client: " + client.getInetAddress().getHostAddress()); System.out.println("New client: " + client.getInetAddress().getHostAddress());
ClientHandler clientSock = new ClientHandler(client); ClientHandler clientSock = new ClientHandler(client);
new Thread(clientSock).start(); ExecutorService executorService = Executors.newFixedThreadPool(2);
executorService.submit(clientSock);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();