JavaFX-when calling functions that take a long time to execute, an error occurs "The Java platform does not work "


Hello, I am writing an application in java. As a GUI I use JavaFX (I will say right away that there is no such problem when using swt).
So, there is a certain function, whose execution time is at least 30 seconds on my laptop. It is quite complex data processing.
When it is called, literally after 1-2 seconds, a window appears that "The Java(TM) Platform SE binary does not work" with the text " Occurred the problem caused the program to stop working...".
I do not know how to solve this problem.
Maybe someone will tell you how to call methods that run for quite a long time and at the same time the JavaFX application did not cut down like this..?
Calling the method when selecting a pop-up menu item:

itemGoIT.setOnAction(new EventHandler<ActionEvent>() {     

   @Override      

   public void handle(ActionEvent event) {      

      context.hide(); //убираем меню

      System.out.println("старт " + new Date(System.currentTimeMillis()));

      JniTest SS = new JniTest();

      try {
          //вызываем метод
          SS.showString();
       }
       catch (UnsatisfiedLinkError e) {
          System.out.println("метод не найден (" + e + ")");
       }

       System.out.println("завершено " + new Date(System.currentTimeMillis()));
    }    
});     
Author: Artem Konovalov, 2017-01-24

1 answers

Most likely, you are hanging a thread that handles ui events.
To prevent this from happening, you need to put all the heavy operations in a separate thread, i.e. your code should look like this:

new Thread(() -> {
        System.out.println("старт " + new Date(System.currentTimeMillis()));

        JniTest SS = new JniTest();

        try {
            //вызываем метод
            SS.showString();
        } catch (UnsatisfiedLinkError e) {
            System.out.println("метод не найден (" + e + ")");
        }

        System.out.println("завершено " + new Date(System.currentTimeMillis()));
    }).start();
 1
Author: Artem Konovalov, 2017-01-24 08:56:59