Skip to content

Commit 127367b

Browse files
committed
Perform the persistence asynchronously to not block the main (UI) thread
This avoids "your app is not responding" errors, while the git command is waiting for password input to load the gpg key for commit signing. This also reverts the fix from 7cc0463: Calling System#exit immediately after Platform#exit prevents Application#stop from being called. And we always exited with 0. Now the exit status is determined by DesignerStarter#launchGui and used correctly. Platform#exit triggers the shutdown of JavaFx. After that is done execution continues in DesignerStarter after Application#launch.
1 parent 64b89c6 commit 127367b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/java/net/sourceforge/pmd/util/fxdesigner/Designer.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javafx.application.Application;
2222
import javafx.application.Platform;
2323
import javafx.collections.ObservableList;
24+
import javafx.concurrent.Task;
2425
import javafx.fxml.FXMLLoader;
2526
import javafx.scene.Parent;
2627
import javafx.scene.Scene;
@@ -97,11 +98,18 @@ public void start(Stage stage, DesignerRoot owner) throws IOException {
9798
));
9899

99100
stage.setOnCloseRequest(e -> {
100-
owner.getService(DesignerRoot.PERSISTENCE_MANAGER).persistSettings(mainController);
101-
Platform.exit();
102-
// VM sometimes fails to exit for no apparent reason
103-
// all our threads are killed so it's not our fault
104-
System.exit(0);
101+
Task<Void> closerTask = new Task<Void>() {
102+
@Override
103+
protected Void call() throws Exception {
104+
owner.getService(DesignerRoot.PERSISTENCE_MANAGER).persistSettings(mainController);
105+
return null;
106+
}
107+
};
108+
closerTask.setOnSucceeded(event -> {
109+
Platform.exit();
110+
});
111+
new Thread(closerTask).start();
112+
e.consume(); // don't close the window yet, will be closed by Platform#exit
105113
});
106114

107115
Parent root = loader.load();

0 commit comments

Comments
 (0)