#Thread dont start

5 messages · Page 1 of 1 (latest)

compact adder
#

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?
unkempt nicheBOT
#

This post has been reserved for your question.

Hey @compact adder! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

drifting wind
#

How do you know that it doesn't continue?

tulip rock