On Wed, 7 May 2025 13:06:50 GMT, Kevin Rushforth <k...@openjdk.org> wrote:
>> `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. @kevinrushforth ... what about manipulating a Scene that was at some point attached to a Window? I mean, I've built a solution specifically for just-in-time registration **and** unregistration of listeners. So IMHO when a Scene is detached or the window is no longer showing (basically any time it doesn't have a peer) then listeners need to detach as well (and re-attach when that situation changes again). ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/1655#discussion_r2077627120