RFR: 8308588: Unnecessary synchronized on GTKStyle#ICONS_MAP can be removed
Alexey Ivanov
aivanov at openjdk.org
Thu Aug 29 12:45:20 UTC 2024
On Thu, 29 Aug 2024 05:20:20 GMT, Tejesh R <tr at openjdk.org> wrote:
> > > One slight concern is that, does GTKStockIcon has any role to play with synchronized block?
> >
> >
> > Sorry, I didn't understand what do you mean.
>
> I meant, since `ICONS_MAP` stores `GTKStockIcon` as value, I was wondering does that make any difference or need for the map to be synchronized?
In fact, `synchronized` block around `ICONS_MAP.get` had no effect.
To be correct, the value for `ICONS_MAP` had to be assigned inside a `synchronized` block too. Otherwise, it is not thread-safe.
> I also came across Immutable Maps which are inherently thread safe. If ICONS_MAP are immutable one, then Synchronized block is definitely redundant.
Effectively, `ICONS_MAP` is an immutable map. It's initialised in a static initialiser and is never modified afterwards.
As far as I can tell, `GTKStockIcon` objects stored in the map aren't modified either.
Thus, the entire structure is immutable and is thread-safe without additional synchronisation.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/20741#issuecomment-2317545926
More information about the client-libs-dev
mailing list