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();
}
});
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
I currently had this problem while using an ThreadExecutor in the controller. Application does not exit if the ThreadExecutor is not shutdown. See here: how-to-shut-down-all-executors-when-quitting-an-application
As it can be a problem to recognize an application exit in the controller, you can get a reference to the controller from your Application class like so (using the sample application from Eclipse):
Your Application overrides the stop method, where you can call a housekeeping method of the controller (i use a method called startHousekeeping):
You could close your application by clicking close Button , with some code.
I was able to fix this problem by calling
com.sun.javafx.application.tkExit()
. You can read more in my other answer here: https://stackoverflow.com/a/22997736/1768232 (these two questions really are duplicates).The only way was to call 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.
First Look Here