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

Guru Hb ghb at openjdk.java.net
Mon Jul 26 14:22:12 UTC 2021


On Mon, 26 Jul 2021 14:16:39 GMT, Guru Hb <ghb at openjdk.org> wrote:

>> 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?
>
> We could have created a Singleton in field declaration if below points were true :  
> 1. If we had only "PresetRepository" as a main class with Singleton (Currently this is a factory).
> 2. Likelihood of "PresetRepository" object required all the time of JMC's lifecycle . 
> + "- does it really have to be lazily created?"
> 3. Singleton Object + init (PresetRepository.addLocalPresetTo(...) ) is doing a File Operation.

> Actually, singleton field need also to be `volatile`.
> see https://shipilev.net/blog/2014/safe-public-construction/ for more info

Thanks @jpbempel that was an informative article and added `volatile` to the field declaration, with this neither Fortify nor apptest complained.

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

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


More information about the jmc-dev mailing list