RFR: 8349091: Charts: exception initializing in a background thread [v6]

Kevin Rushforth kcr at openjdk.org
Tue Mar 4 16:30:10 UTC 2025


On Mon, 3 Mar 2025 21:42:26 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

>> The above does require though that `Platform.accessibilityActiveProperty()` is properly synchronized.  I think it may be a good idea to fix that first.  Perhaps all platform provided properties (if there are more) should ensure they're only initialized once.
>
> unrelated, but I would rather disallow background access to any platform properties.
> 
> _per the earlier email_, this might (read: will) create concurrent access when the node is not yet attached to the scene graph:
> 
> 
> background thread                   fx app thread
> 1. start creating the node
> 2. add listener to platform prop
> 3. keep initializing the node        <-- platform property change notification
> 4. some more code
> 
> 
> step 3 is when concurrent access occurs.

There is an even more fundamental problem: JavaFX properties are not thread-safe. You cannot safely add a listener or binding to a property in one thread while another thread modifies that property's value.

So I think that deferring the binding to `Platform::accessibilityActiveProperty` is the only viable approach.There might still be an opportunity to simplify it a bit along the lines of what John mentions, as long as the code that binds to the property is guaranteed to be run on  the FX application thread.

We can be certain that setting the window property to a non-null value only happens on the FX app thread (`Stage::setScene` enforces that threading constraint).

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1697#discussion_r1979801247


More information about the openjfx-dev mailing list