It is incorrect to call code that leads to changes in the user interface from a thread other than the FX application thread, regardless of whether it throws an exception. The FX toolkit does its best to throw an exception if you violate this rule, but in some cases the performance impact is too great to run the test. If you create these bindings, any subsequent changes to the properties to which you are bound must be made in the FX application thread. Ie, if you are working in a background thread, you must change the properties using code, for example:
Platform.runLater(() -> CacheManager.progress.set(...));
and
Platform.runLater(() -> CacheManager.status.set(...));
Since you probably don't want your service code to bind to JavaFX (via the Platform class), you might consider using listeners instead of bindings and scheduling updates from listeners:
CacheManager.progress.addListener((obs, oldValue, newValue) -> Platform.runLater(() -> progressBar.setProgress(newValue.doubleValue()))); CacheManager.status.addListener((obs, oldStatus, newStatus) -> Platform.runLater(() -> someLabel.setText(newStatus)));
If you replace the bindings with these listeners, you can update the properties in any thread.
source share