There is a thread that performs large calculations, and after collecting all the data, they need to be displayed in the UI, but at the same time, while the thread is running, the interface gets a stake because of the while loop that waits for the thread to finish, to start displaying information on the graphs.
Here is the startup code:
@FXML void Start() throws UnsupportedFlavorException, InterruptedException, IOException { Programm p = new Programm(); GlobalConstants gc = new GlobalConstants(); Indicator.setVisible(true); p.ReadFrame(); while (true) { synchronized (gc) { if (gc.flag == 3) { labelPredict.setText(String.valueOf(String.format("%.3f", gc.predict * 1000)) + "мм"); ChartSpeedSetter(); ChartCoordSetter(); ChartCoordPDSetter(); ChartSpeedPDSetter(); //ChartLeftFrimeSetter(); Indicator.setVisible(false); break; } } } } the Start function is started by the button, then from another class the function is started with the calculations of p.ReadFrame ();
And in while the variable from the stream is synchronized, which at the end of the work sets the flag = 3, while while the stream is running ReadFrame is needed so that the interface does not get up with a stake, but at the end it fills the graphics.
PS I tried through the task and service, the task cannot change the UI element, or I do it wrong (everywhere there are examples with the ProgressBar update). he just swears at the functions that I pass to him.