gpt4 book ai didi

javafx - AnimationTimer 是否在自己的线程中运行?

转载 作者:行者123 更新时间:2023-12-02 11:52:12 24 4
gpt4 key购买 nike

JavaFX 的 AnimationTimer 启动时是否在单独的线程上运行?

我在调试器中运行了一个 JavaFX 应用程序,无论有没有 AnimationTimer,在这两种情况下都有 6 个线程在运行。另外,JavaDocs 没有提到它实现 Runnable

这表明它不是在自己的线程中运行,但就其本质而言,我认为它需要在自己的线程中运行以确保它按足够规律的时间表运行。

如果它不在自己的线程中运行,它是否只是在创建它的线程中运行?这是否意味着如果我在 Applicationstart() 内部创建 AnimationTimer,可以安全地从 Timer 内修改 UI 元素?

最佳答案

Does JavaFX's AnimationTimer run on a separate thread when launched?

不,事实并非如此。它在 JavaFX 应用程序线程上运行。当 AnimationTimer 处于事件状态时,在每一帧中都会调用 AnimationTimer 的 handle() 方法。通常,JavaFX 会尝试保持 60 fps 的帧速率。

Does that mean it's safe to modify UI elements from within the Timer if I create the AnimationTimer inside of Application's start()?

是的,确实如此。由于它在 JavaFX 应用程序线程上运行,因此修改场景图元素是完全可以的。只需确保您没有在 handle() 中进行大量计算即可。

关于javafx - AnimationTimer 是否在自己的线程中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33068953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com