On Wed, 7 May 2025 09:16:02 GMT, Michael Strauß <mstra...@openjdk.org> wrote:

>> PlatformPreferences.update() seems to be called only from the fx thread, if 
>> I read the code right.  What happens when the Scene is created in a bg 
>> thread and a listener added to its preferences, and an event is fired?  Will 
>> the statement `#1` be still valid?  (I don't see any code that delays the 
>> dispatch until after the Scene is shown).
>> 
>> `#2` - all this is good, but we seem to hand the gun to user and say: here, 
>> shoot yourself in the foot.  And they do.  I think it (creating things in a 
>> background thread) was a mistake in the first place, but there seems to be 
>> zero desire to change it, so who am I to say otherwise?
>
> `NullCoalescingPropertyBase` (used in `ScenePreferences`) is initially 
> disconnected. It will set its initial value to the value is reads from 
> `PlatformPreferences`, but it will not subscribe to change notifications. The 
> reason for this is to prevent a scene that is created on a background thread 
> from immediately receiving change notifications on the FX thread, which could 
> not only potentially corrupt the property state (because they're not 
> concurrently thread-safe), but also mess up the application state.
> 
> When the scene is shown, `NullCoalescingPropertyBase` will subscribe to 
> change notifications from `PlatformPreferences`, because now we're safely on 
> the FX thread. The code for that is in ScenePreferences:L142.

> I think it (creating things in a background thread) was a mistake in the 
> first place, but there seems to be zero desire to change it

Your objection is noted, but we are not going to relitigate this. JavaFX 
explicitly allows creation and modification of a scene graph on a thread other 
than the JavaFX application thread up to the point before that scene is 
attached to a window.

This means that we do need to be careful in our implementation, especially 
avoiding anything that might run on the application thread prior to the scene 
becoming "live". Sometimes that means deferring the adding of listeners as was 
recently done for charts. It sounds like that's what is being done here by 
deferring the subscription to platform preferences until the scene is shown.

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1655#discussion_r2077589320

Reply via email to