Java Reference
In-Depth Information
Best Practices for
Practitioners of JavaFX can easily abuse its ease of use to create applications that perform
and scale poorly. This section provides a list of some practices that should help you avoid
performance or usability penalties.
F Declare your variables using the def keyword —always use the def keyword to declare
your variable, unless you know for certain that the variable will be updated later or is
a bound variable.
F Stay off the EDT —JavaFX applications are inherently single-threaded running on one
special thread called the Event Dispatch Thread (EDT). All GUI activities are handled
on the EDT. If you execute long-running processes directly in your JavaFX code, they
will degrade the responsiveness of the UI or make it outright unusable. JavaFX offers
the Task API, which is designed to provide the mechanism to execute processes
F You can do this in three steps:
1. Create a Java class that implements javafx.async.RunnableFuture and
overrides the run() method, which contains the asynchronous code that you
want to run:
public class LongRunningRunnable implements RunnableFuture {
private long limit = Long.MAX_VALUE ;
public LongRunningRunnable (long l){limit = l;} // constructor
public void run() throws Exception {
for(int i = 0; i < limit; i++){
Search WWH ::

Custom Search