这个例子简单,消耗高CPU,是bug还是设计技术失败? 细节:让程序运行并注意CPU消耗正在增加......
许多程序员,像我一样,像javafx,当这种方法弹出时,帖子工作人员应该把setCache(true); 但显然它没有解决。
我也认为Platform.runLater,当有很多它进入队列并最终损害使用太多的CPU时。
问题出在哪里,我希望该地区的同事检查你的javafx是否遇到同样的错误!!?
在Ubuntu中,我打开了teminal并调用了#34; top",并打开了cpu使用情况统计信息的图形显示,确实出现了问题。
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运行时环境(构建 1.8.0_112-b15)Java HotSpot(TM)64位服务器VM(内置25.112-b15,混合模式)
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);
}
}
由于