问题描述
JavaFX应用程序线程.我可以找到的消息来源说,节点上的所有更新都必须在此线程中发生.
The JavaFX Application Thread. Sources I can find says all updates on nodes must happen in this thread.
我正在寻找有关此规则以及此规则是否有例外的文档. https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm 如它所说:
I am trying to find the documentation for this and if there are any exceptions to this rule.https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htmAs it says:
https://docs .oracle.com/javase/8/javafx/get-started-tutorial/jfx-architecture.htm#A1107438
我经历过,并非必须在JavaFX AT上完成节点上的所有更新.在该线程外,一些用于更新节点的调用可以正常工作.例如,更新Text textProperty不需要在JavaFX AT中运行.因此,设置工具提示似乎也不是,或者更改了可见性/禁用/受管理.
I have experienced that not all updates on a node must be done on the JavaFX AT. Some calls to update the node works fine outside this thread.For instance updating Text textProperty does not require running within the JavaFX AT. Nor thus it looks like setting tooltip does either, or changing visibility/disable/managed.
JavaFX AT以外的Label textProperty的更新将抛出
Updates on Label textProperty outside of the JavaFX AT will throw an
IllegalStateException:不在FX应用程序线程上; currentThread =任务
IllegalStateException: Not on FX application thread; currentThread = Task
推荐答案
您正在将不允许的内容与引发异常的内容混淆.仅仅因为某些东西不会引发异常并不意味着它是允许的,或者它是安全的,或者保证它可以正常工作.
You are confusing what is not allowed with what throws exceptions. Just because something doesn't throw an exception doesn't mean it is allowed, or that it is safe, or that it is guaranteed to work.
对实时场景图的一部分节点的所有更改必须都发生在JavaFX Application Thread上.
All changes to nodes that are part of a live scene graph must happen on the JavaFX Application Thread.
如果违反此规则,JavaFX将尽最大努力抛出异常.检查线程会浪费时间,并且对于某些操作而言,检查线程的性能开销会太高,因此并非所有违反规则的行为都会导致异常.但是,即使没有引发异常,违反规则也很容易在将来的任意时间出现不一致的行为.请参阅运动圈随机消失(javafx),以了解这种情况在实践中的发生情况.
JavaFX makes a best effort to throw exceptions if this rule is violated. Checking the thread costs time, and for some operations the performance cost of checking the thread is too high, so not all violations of the rule will result in an exception. However, violating the rule is prone to inconsistent behavior at arbitrary times in the future, even if no exception is thrown. See Moving circle randomly disappears (javafx) for an example of this happening in practice.
这篇关于在应用程序线程外更新JavaFX Live节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!