Skip to content

Commit a99cb90

Browse files
committed
Merge pull request #69 from adangel:async-exit
Perform the persistence asynchronously to not block the main (UI) thread #69
2 parents 64b89c6 + 371d479 commit a99cb90

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**Merged pull requests:**
1414

1515
* [#68](https://github.com/pmd/pmd-designer/pull/68) Expose all properties with default values by [@jsotuyod](https://github.com/jsotuyod)
16+
* [#69](https://github.com/pmd/pmd-designer/pull/69) Perform the persistence asynchronously to not block the main (UI) thread #69 by [@adangel](https://github.com/adangel)
1617

1718
See https://github.com/pmd/pmd-designer/milestone/11
1819

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)