On Fri, 7 Feb 2025 16:33:27 GMT, Andy Goryachev <ango...@openjdk.org> wrote:

>> Thread-safe and re-entrant implementation of Utils.
>> 
>> The new code still uses the static instances of Text and TextLayout for 
>> performance reasons, but adds a thread-safe mechanism to keep track of 
>> whether any of the instances is in use and when that happens, supplies a new 
>> instance instead.  This solves both thread safety and re-entrancy.
>
> Andy Goryachev has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   review comments

To add a little more to what Andy said, I think there are three main approaches 
that could have been used here:

1. Remove the static fields and always allocate a new object each time it is 
needed.
2. Keep the static fields for the common case where there is only one thread 
(typically the JavaFX application thread); check and allocate a new object if 
the static fields are already in use
3. Replace the static fields with ThreadLocalStorage

There might be other solutions, but we don't want anything too complicated. 
Andy decided to go with 2.

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

PR Comment: https://git.openjdk.org/jfx/pull/1691#issuecomment-2643463999

Reply via email to