This content has been marked as final. Show 2 replies
1 person found this helpful
Shall i implement my my message receiver as thread in which i would then use a platform.RunLater() ?Yes.
Or shall i use a Task ?No.
what is the logic behind each method?A general rule of thumb:
a) If the operation is initiated by the client (e.g. fetch data from a server), use a Task for a one-off process (or a Service for a repeated process):
- the extra facilities of a Task such as easier implementation of thread safety, work done and message properties, etc. are usually needed in this case.
b) If the operation is initiated by the server (e.g. push data to the client), use Platform.runLater:
- spin up a standard thread to listen for data (your network communication library will probably do this anyway) and to communicate results back to your UI.
- likely you don't need the additional overhead and facilities of a Task in this case.
Tasks and Platform.runLater are not mutually exclusive. For example if you want to update your GUI based on a partial result from an in-process task, then you can create the task and in the Task's call method, use a Platform.runLater to update the GUI as the task is executing. That's kind of a more advanced use-case and is documented in the Task documentation as "A Task Which Returns Partial Results" http://docs.oracle.com/javafx/2/api/javafx/concurrent/Task.html
Thinks are much more clear now. Actually my program is currently working with SWT and this is what i do, 9but new requirements came, and i have to revamp the all interface with JavaFx 2. However, when i start looking at the official tutorial on concurrency i automatically got lost. As there is no mention at all of the Platform.runLater....
Many thx again, i got the point with the non exclusivity as well.