Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Multithreading

Knut Arne VedaaNov 10 2011 — edited Nov 15 2011
I have an application which performs a long-running computation. The obvious thing to do is move this into a different thread. However I'm not quite sure how to do that in JavaFX, specifically how the threads can interact.

1) When I run the computation on the application thread, if I set the text of a label to e.g. "Starting computation..." before I start the computation, the label will not be updated before after the computation has finished. If the rendering is done in a seperate thread from the application thread, why doesn't it update the UI immediately?

2) How can I use the concurrent features of JavaFX (Service, Worker, Task) to perform the computation in a background thread?

3) How can I update the UI from the background thread (e.g. updating a progress bar)? The doc says:
JavaFX application thread: This is the primary thread used by JavaFX application developers. Any “live” scene, which is a scene that is part of a window, must be accessed from this thread.
What's the meaning of "access" here? Does it mean that I cannot call any methods on UI elements from other threads than the application thread?

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 13 2011
Added on Nov 10 2011
9 comments
1,183 views