RFR: 7357: Double-Checked Locking in Agent Plugin code [v2]

Marcus Hirt hirt at openjdk.java.net
Mon Jul 26 13:51:07 UTC 2021


On Mon, 26 Jul 2021 10:21:33 GMT, Jean-Philippe Bempel <jpbempel at openjdk.org> wrote:

>> Guru Hb has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Fixing formatting error
>
> application/org.openjdk.jmc.console.agent/src/main/java/org/openjdk/jmc/console/agent/manager/model/PresetRepositoryFactory.java line 53:
> 
>> 51: 		if (singleton == null) {
>> 52: 			synchronized (PresetRepositoryFactory.class) {
>> 53: 				singleton = create();
> 
> Actually, singleton field need also to be `volatile`.
> see https://shipilev.net/blog/2014/safe-public-construction/ for more info

Indeed. I haven't checked, but couldn't all this be avoided by simply creating the singleton at the field declaration - does it really have to be lazily created?

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

PR: https://git.openjdk.java.net/jmc/pull/282


More information about the jmc-dev mailing list