首页 > 解决方案 > ProgressIndicator 在不确定模式下花费大量 CPU (JavaFX)

问题描述

我的节点显示连接到我的 PC 的设备。在未连接时,显示处于不确定模式 (progress=-1) 的 progressIndicator(并显示消息“设备未打开”)。但我对 CPU 使用率有疑问 - 虽然 progressIndicator 不确定,但 CPU 使用率非常高(接近 20%)。当我打开设备时,progressIndicator 被隐藏,CPU 使用率变为 1% 或 2%。即使在这个示例中,一个 progressIndicator 处于不确定模式,我的 CPU 使用率也接近 12%:

import javafx.application.Application;
import javafx.scene.CacheHint;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Del extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Scene scene = new Scene(getTestGridPane());

        primaryStage.setTitle("Welcome to JavaFX!");
        primaryStage.setScene(scene);
        primaryStage.sizeToScene();
        primaryStage.show();
    }

    public GridPane getTestGridPane() {
        GridPane gridPane = new GridPane();
        ProgressIndicator mp = new ProgressIndicator();
        mp.setCache(true);
        mp.setCacheHint(CacheHint.SPEED);
        mp.setCacheShape(true);

        gridPane.add(mp, 0, 0);
        return gridPane;
    }
} 

如何长时间使用处于不确定状态的progressIndicator?

标签: javafx

解决方案


推荐阅读