ProgressIndicator在不确定模式下花费大量CPU(JavaFX)
“我的节点”显示连接到我的电脑的设备。未连接时,将显示不确定模式下的progressIndicator(进度=-1)(并显示消息“设备未打开”)。但是我在CPU使用率方面有问题-虽然progressIndicator是不确定的,但CPU使用率非常高(接近20%)。当我打开设备时,progressIndicator被隐藏,CPU使用率变为1%或2%。 即使在这个例子中,一个progressIndicator处于不确定模式,我的CPU使用率也接近12%:ProgressIndicator在不确定模式下花费大量CPU(JavaFX),javafx,Javafx,“我的节点”显示连接到我的电脑的设备。未连接时,将显示不确定模式下的progressIndicator(进度=-1)(并显示消息“设备未打开”)。但是我在CPU使用率方面有问题-虽然progressIndicator是不确定的,但CPU使用率非常高(接近20%)。当我打开设备时,progressIndicator被隐藏,CPU使用率变为1%或2%。 即使在这个例子中,一个progressIndicator处于不确定模式,我的CPU使用率也接近12%: import javafx.applicat
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;
}
}
如何在indceterminate状态下长时间使用progressIndicator?第一次运行代码时,我在Task Manager上看到CPU占80%。然而,在第二次、第三次和第四次运行您的代码时,CPU的启动率刚刚超过10%,但很快就下降到2%。我正在Windows 10 64位上使用JDK 13.0.2。谢谢您的回答!我使用JDK1.8.0¿,因为它与其他旧项目相连。我将尝试在新的JDK中进行测试第一次运行代码时,我在TaskManager上看到CPU为80%。然而,在第二次、第三次和第四次运行您的代码时,CPU的启动率刚刚超过10%,但很快就下降到2%。我正在Windows 10 64位上使用JDK 13.0.2。谢谢您的回答!我使用JDK1.8.0¿,因为它与其他旧项目相连。我将尝试使用新的JDK进行测试