Java Reference
In-Depth Information
2. Next, create a JavaFX class that extends
javafx.aysync.JavaTaskBase
and
overrides
function create():RunnableFuture
, which returns an instance
of the newly-defined Java class above to be executed in its own thread:
public class
LongRunningTask
extends
JavaTaskBase
{
public-init var limit =
Long.MAX_VALUE
;
override protected
function
create
()
:
RunnableFuture
{
new
LongRunningRunnable
(limit);
}
}
3. Lastly, use the JavaFX class (defined above) to start your long-running process on its
own thread:
var t = LongRunningTask{limit:Byte.MAX_VALUE}
t.start(); // start task on its own thread
F
Reuse image objects—if
—if you have an image that appears in multiple places, load the
image once using the
Image
object, then reuse the
Image
instance in any image
number of
ImageView
instances. That way, you don't have duplicated bytes wasting
memory resources.
F
Scale media to size
—avoid using images or videos at larger resolutions than
needed. When possible, encode your media to the size and resolution that you
will actually need. This will avoid unnecessary scaling transformation penalties
when scaled in JavaFX.
F
Turn off smooth
—when your scene graph contains a large number of shapes, you
can gain performance by setting the
smooth
property to
false
in order to reduce
the overhead required for anti-aliasing wherever possible.
F
Cache your visual nodes
—when the scene graph engine paints its node on the
screen, you can avoid repaint penalties by caching complex non-rotated object
graphs. Caching causes the engine to reuse previously rendered images, rather
then repainting the scene every time.
F
Remove instead of hide
—to keep your node rendering time down, and increase
performance, you should delete objects from the scene graph instead of setting
property
visible
to
false
whenever possible.
F
Avoid Gratuitous Effects and Animations
—effects (paint, transformation, scale, and
so on) and animations incur processing overhead, especially with large numbers of
nodes. Avoid applying effects and animations unless absolutely necessary.
F
Ungroup paint effects
—when your nodes are encapsulated in a
Group
instance,
apply your effects to individual nodes instead of the
Group
node. This provides
granular control of where the effects are applied and helps avoid necessary
rendition of effects.