There is a ToggleButton
button, when pressed, the server framework should be launched from the code in a separate thread.
there is no possibility to terminate the server normally, separately in the console it ends via Ctrl+C
It is necessary that when the ToggleButton
button is activated, the server works, and when it is deactivated ( selest=false
), the thread selest=false
and the variable is released for re-activation.
Now so does not work
Thread threadTerminalServer; boolean init = false; @FXML private void handleButtonTerminalServer(ActionEvent event) { if (init == false) { threadTerminalServer = new Thread(new Runnable() { @Override public void run() { StartTerminalServer startTerminalServer = null; try { if (buttonTerminalServer.isSelected()) { startTerminalServer = new StartTerminalServer(); System.out.println("Start"); init = true; } } catch (Exception e) { e.printStackTrace(); } } }); } if (buttonTerminalServer.isSelected()) { threadTerminalServer.start(); } else { System.out.println("Stop-1"); threadTerminalServer.stop(); init = false; threadTerminalServer = null; Runtime.getRuntime().gc(); } }
Thread.interrupt()
? - Barmaley