AnimationTimer是否在其自己的线程中运行? [英] Is AnimationTimer running in its own thread?

查看:55
本文介绍了AnimationTimer是否在其自己的线程中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我在带有和不带有AnimationTimer的调试器中运行JavaFX应用程序,并且在两种情况下均运行6个线程.另外,JavaDocs并未提及它实现了Runnable.

I ran a JavaFX application in a debugger, with and without a AnimationTimer, and in both cases there were 6 threads running. Plus, the JavaDocs don't mention it implementing Runnable.

这表明它不是在自己的线程中运行,但是从本质上来说,我认为它需要在自己的线程中运行,以确保它能够以足够的时间表运行.

That suggests that it's not run in its own thread, but by its very nature, I'd think it would need to run in its own thread to ensure it runs in a regular enough schedule.

如果它不是在自己的线程中运行,那么它只是在创建它的任何线程中运行吗?

And if it's not run in its own thread, is it just run in whatever thread creates it? 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的AnimationTimer在启动时是否在单独的线程上运行?

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

不,不是.它在JavaFX应用程序线程上运行.在激活AnimationTimer时,每帧中都会调用AnimationTimer的handle()方法.通常,JavaFX会尝试保持 60 fps 的帧速率.

No, it doesn't. It runs on the JavaFX application thread. The AnimationTimer's handle() method is called in every frame while the AnimationTimer is active. Normally, JavaFX tries to maintain a frame rate of 60 fps.

这是否意味着如果我在Application的start()内部创建AnimationTimer,则可以安全地在Timer中修改UI元素?

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()中进行大量计算即可.

Yes, it is. Since it runs on the JavaFX application thread, it is perfectly fine to modify scene graph elements. Just make sure you are not doing heavy computation in the handle().

这篇关于AnimationTimer是否在其自己的线程中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆