且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在哪个线程上执行JavaFX更改侦听器?

更新时间:2023-02-12 08:24:30

一般来说,更改侦听器在同一个线程上运行,更改是制作。当然,可能会有 Property ObservableValue 的实现,它们在另一个线程上调用侦听器,但就我而言我知道没有这种行为的默认实现。

Generally speaking, change listeners run on the same thread the change was made on. Of course, there could be implementations of Property or ObservableValue which call the listener on another thread, but as far as I'm aware there are no default implementations with this behavior.

所以简单的答案是 - 更改侦听器将在原始更改执行的任何线程上运行。

如果说属性是与JavaFX节点相关的原始更改应该在JavaFX线程上调用,以防止Not on FX应用程序线程异常。

So the simple answer is - the change listener will run on whichever thread the original change was performed.
That being said, if the property is related to a JavaFX node, the original change should have been called on the JavaFX thread to prevent a "Not on FX application thread" exception.