I have a JavaFX application and invoke the following code with a Button click.
new Thread(() -> {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4558);
Socket accept = serverSocket.accept();
} catch (IOException e) {
e.printStackTrace();
}
}).run();
With the thread, I want to prevent that the UI will be frozen, but the application has not returned any feedback, after serverSocket.accept(). The port is not blocked.
Does anyone know why? Thanks in advance!
When starting a
Thread, don't call therun()method but thestart()one.Code would be like this: