This example simple, consume high cpu , is bug or design technology failure ? Detail: let the program run and note that the CPU consumption is increasing...
Many programmers, like me, like javafx, and when that kind of approach pops up, the post staff should put setCache(true); But apparently it is not solving.
I also think that Platform.runLater, when there are many it goes to the queue and ends up harming the use too much of the cpu.
Where does the problem come from, I would like colleagues in the area to check if the javafx of you is experiencing the same error !!?
Here in Ubuntu I opened the teminal and called the "top", and also opened the graphical display of cpu usage statistics, and there really is something wrong.
Ubuntu 14.04.1
Prism pipeline init order: es2 sw Using java-based Pisces rasterizer Using dirty region optimizations Not using texture mask for primitives Not forcing power of 2 sizes for textures Using hardware CLAMP_TO_ZERO mode Opting in for HiDPI pixel scaling Prism pipeline name = com.sun.prism.es2.ES2Pipeline Loading ES2 native library ... prism_es2 succeeded. GLFactory using com.sun.prism.es2.X11GLFactory (X) Got class = class com.sun.prism.es2.ES2Pipeline Initialized prism pipeline: com.sun.prism.es2.ES2Pipeline Maximum supported texture size: 16384 Maximum texture size clamped to 4096 Non power of two texture support = true Maximum number of vertex attributes = 16 Maximum number of uniform vertex components = 16384 Maximum number of uniform fragment components = 16384 Maximum number of varying components = 128 Maximum number of texture units usable in a vertex shader = 16 Maximum number of texture units usable in a fragment shader = 16 Graphics Vendor: X.Org Renderer: Gallium 0.4 on AMD ARUBA (DRM 2.43.0, LLVM 3.8.0) Version: 3.0 Mesa 11.2.0 vsync: true vpipe: true new alphas ES2ResourceFactory: Prism - createStockShader: Texture_LinearGradient_PAD.frag new alphas ES2ResourceFactory: Prism - createStockShader: Solid_TextureRGB.frag
PPSRenderer: scenario.effect - createShader: Blend_HARD_LIGHT PPSRenderer: scenario.effect - createShader: LinearConvolveShadow_24
java version "1.8.0_112" Java(TM) SE Runtime Environment (build 1.8.0_112-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.CacheHint;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class AnimatedTeste extends Application {
@Override
public void start(Stage primaryStage) {
ImageView imv = new ImageView("http://icons.iconarchive.com/icons/icons-land/sport/16/Tennis-Ball-icon.png");
Label label = new Label("");
label.setGraphic(imv);
Timeline tl = new Timeline(new KeyFrame(
Duration.millis(500),
new KeyValue(label.layoutYProperty(), label.getLayoutY()+15 ),
new KeyValue(label.rotateProperty(), 360)
));
tl.setAutoReverse(true);
tl.setCycleCount(Timeline.INDEFINITE);
tl.play();
Group root = new Group();
root.getChildren().add(label);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Thanks