Hey i need help my Code dont work well.
private static final int BUFFER_SIZE = 1024;
private static final int THREAD_POOL_SIZE = 10;
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
public static void main(String[] args) {
Executor threadPool = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
try (ServerSocket serverSocket = new ServerSocket()) {
serverSocket.bind(new InetSocketAddress(12345));
while (true) {
Socket socket = serverSocket.accept();
threadPool.execute(() -> handleConnection(socket));
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Error accepting connection", e);
}
}
private static void handleConnection(Socket socket) {
try (InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream()) {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = input.read(buffer);
Thread.yield();
output.write(buffer, 0, bytesRead);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Error handling connection", e);
}
}```
I am trying to slow down my own network with the program but I have the problem that the code does not continue from this point: `threadPool.execute(() -> handleConnection(socket));` Is this perhaps due to the firewall?