0

I have follow abstract class, with init() and stop() methods: (issue in stop() method)

public abstract class AbstractJavaFxApplication extends Application {

    private static String[] fxArgs;

    protected ConfigurableApplicationContext applicationContext;

    @Override
    public void init() throws Exception {
        applicationContext = SpringApplication.run(getClass(), fxArgs);
        applicationContext.getAutowireCapableBeanFactory().autowireBean(this);
    }

    @Override
    public void stop() throws Exception {
        System.out.println("STOP");
        applicationContext.stop();
        super.stop();
    }

    protected static void launchApp(Class<? extends AbstractJavaFxApplication> clazz, String[] args){
        fxArgs = args;
        Application.launch(clazz, args);
    }
}

And main class, which extends the AbstractJavaFxApplication:

@SpringBootApplication
public class WeightliftingviewerApplication extends AbstractJavaFxApplication{

    @Value("First attempt")
    private String tittle;

    @Qualifier("mainView")
    @Autowired
    private ControllersConfiguration.ViewHolder view;

    public static void main(String[] args) {
        launchApp(WeightliftingviewerApplication.class, args);
//      SpringApplication.run(WeightliftingviewerApplication.class, args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle(tittle);
        primaryStage.setScene(new Scene(view.getView()));
        primaryStage.setResizable(true);
        primaryStage.centerOnScreen();
        primaryStage.show();
    }
}

Issue in that, what, when I close application I expectedly will hit in stop() method and gets STOP in console. But application not stopped and yet running in process

Valentyn Hruzytskyi
  • 1,772
  • 5
  • 27
  • 59
  • Do you use `JxBrowser` in your application ? I am asking because some libraries, like `JxBrowser`, need to be specificly stopped. – Pagbo Nov 26 '18 at 12:30

1 Answers1

1

Try this in your Stop Method :

@Override
public void stop() throws Exception {
    System.out.println("STOP");
    Platform.exit();
    System.exit(0);
}
Mohamed Benmahdjoub
  • 1,270
  • 4
  • 19
  • 38
  • Thanks. Whats means `Platform` class? And it is the necessaryto use? - just `System.exit` well helped me without it – Valentyn Hruzytskyi Nov 26 '18 at 19:36
  • 1
    @ValentynHruzytskyi `System.exit(0)` closes the Java Virtual Machine (JVM) (Thus, killing every java process) while `Platform.exit();` signals the JavaFX Toolkit to stop (run the stop function actually). `Platform.exit()` will not necessarily close all the processes (though It can be enough to close all of them, I think you don't necessarily need it, because `System.exit()` is way more than what you wanted) Check this link : https://stackoverflow.com/a/46060236/3745908 for more information. – Mohamed Benmahdjoub Nov 27 '18 at 12:13