0

I am doing a GET request by JAVA, and this take some time, I've shown a loading window, but it crashes until the GET request finishes.

@FXML
    private void recogerDatos() throws IOException, InterruptedException {
        System.out.println("Haciendo la peticion GET a " + ip + ":" + puerto);
        respuestaStruct = getRequest(); 
        for (int i = 0; respuestaStruct.isHaFallado() == false && i < 6; i++) {
            System.out.println("Intennto:"+i);
            Thread.sleep(3000);
            respuestaStruct = getRequest(); 
        }if (respuestaStruct.isHaFallado() == true) {
            System.out.println("GET realizado correctamente.");
            writeDevice.setDisable(false);
        } else {
            System.out.println("Error de la peticion GET");
            mensajeError = true;
        }
        MainApp.loading.close();
}
syam
  • 799
  • 1
  • 12
  • 30
jordi
  • 11
  • 6
  • Please provide a [mcve] that demonstrates the problem. – kleopatra Jul 03 '19 at 10:39
  • 3
    In this case, is better using a Thread for execution an operation od the type Http, with swing exist a component called SwingWorker and in JavaFX exist a component Equivalent called Task. This is a good [post](https://stackoverflow.com/questions/27832347/javafx-swingworker-equivalent) – vincenzopalazzo Jul 03 '19 at 10:41
  • Wrap your function or code that is locking up the program in something like this `new Thread(()->{ YourCodeHere }).start();` – Matt Jul 03 '19 at 12:52

0 Answers0