JavaFX application still running after close


Question

I'm having problem to close my javaFX application, when I click the close button from my stage, my application disappears but if I look for it in my task manager my application still there without close. I've tried to use this code below to force it close the main thread and all childrens threads but the problem persists.

primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

            @Override
            public void handle(WindowEvent t) {
                Platform.exit();
            }

        });
1
17
7/6/2018 1:33:38 PM

Accepted Answer

Does your application spawn any child threads? If so have you ensured that you terminate them (assuming that they're not daemon threads)?

If your application spawns non-daemon threads then they (and therefore your app) will continue to live on until such time you kill the process

23
11/26/2013 9:37:37 AM

The only way was to call System.exit(0);

primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent t) {
                Platform.exit();
                System.exit(0);
            }
        });

[EDITED]

System.exit will just hide your application, if you open SO's manager task your application will be there. The correct way is to check your Threads, one by one and close all before close application.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon