Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8170335

A simple animation consume high cpu

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      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)


      ADDITIONAL OS VERSION INFORMATION :
      ubuntu 14.04.1 64 bits

      Linux jorge-desktop 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Why does such a simple animation consume high cpu ?

      This example simple, consume high cpu , is bug or design technology failure ?

      Because with high use of cpu the computer is slow.

      SetCache to true does not make any difference.

      Missing a really visible and practical example of javaFX, showing how to solve this, at first seems to be caused by a bug.



      REGRESSION. Last worked in version 8u112

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      java -Dprism.verbose=true -com.datagenia.betrader.teste.AnimatedTeste

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      after run example, cpu high 35% and 54%
      ACTUAL -
      after run example, cpu high 35% and 54%

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.animation.KeyFrame;
      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;

      /**
       *
       * @author jorge
       */
      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);
              
              label.setCache(true);
              label.setCacheHint(CacheHint.SPEED);
              label.setCacheShape(true);
              
              // label.setCacheHint(CacheHint.ROTATE);
              
              Timeline tl = new Timeline(new KeyFrame(
                  Duration.millis(500),
                  
                  new KeyValue(label.layoutYProperty(), label.getLayoutY()+15 ),
                  // new KeyValue(label.layoutXProperty(), label.getLayoutX()+30 ),
                  new KeyValue(label.rotateProperty(), 360),
                  new KeyValue(label.cacheHintProperty(), CacheHint.QUALITY),
                  new KeyValue(label.cacheShapeProperty(), true),
                  new KeyValue(label.cacheProperty(), true)
                  ));
                  
          
              tl.setAutoReverse(true);
              tl.setCycleCount(Timeline.INDEFINITE);
              tl.play();
       
              
              Group root = new Group();
              root.getChildren().add(label);
              
              Scene scene = new Scene(root, 300, 250);
              
             // scene.getStylesheets().add( this.getClass().getResource( "../gui/betrader.css").toExternalForm() );
              
              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }
          
      }
      ---------- END SOURCE ----------

            kcr Kevin Rushforth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: