Reputation: 63162
We have a set of scenes for which the intent is to - at a certain point after it is "safe" to do so - save them to image files. "Safe" here means "after some backend work done and also after the scenes are fully painted/rendered."
The single-threaded nature of the FxApplication thread needs to be taken into account : all gui related work needs to happen on the FxApplication thread. So then it is not clear to me how to do arbitrary gui-related operations that require access to the Graphics Context.
the javafx.application.Platform.runLater(runnable)
is intended for short-lived operations. In fact that is how we launch the separate scenes: one scene for each invocation of runLater
. That works fine.
the Task
which is specifically intended for longer running operations. But how should the Task interoperate with the FxApplication thread? There does not seems to be any "queueing mechanism" for the Task to put work back into the FxApplication eventing loop.
We should likely not attempt to perform GUI related ops from the Task - that would violate the FxApplication thread's responsibilities -and lead to race conditions.
Note the following question Platform.runLater and Task in JavaFX does not address this case because the GUI operation shown:
bar.setProgress(counter/1000000.0);
is a "builtin". We need to do arbitrary gui operations.
..
So an outline of how to properly sequence the work would be appreciated.
Upvotes: 0
Views: 368
Reputation: 63162
The following approach is working AFA running GUI operations in the "background" (there is only one GUI thread - so 'background' tasks for GUI operations is a relative term..)
update credit to @jewelsea for a significant chunk of the approach https://gist.github.com/jewelsea/5072743 "Render 300 charts off screen and save them to files in JavaFX."
Platform.runLater
Task
Platform.runLater
that includes:This approach is working: I can see the windows launched, then backend operations happening while the GUI is still responsive: and then eventually - once the backend operations are completed - the additional GUI operations are then performed.
Upvotes: 1