[Rev 01] RFR: 5660: Lazy initialize timestamp unit description
Henrik Dafgård
hdafgard at openjdk.java.net
Wed Dec 11 17:26:32 UTC 2019
On Wed, 11 Dec 2019 15:35:41 GMT, Marcus Hirt <hirt at openjdk.org> wrote:
>> The pull request has been updated with 1 additional commit.
>
> core/org.openjdk.jmc.common/src/main/java/org/openjdk/jmc/common/unit/TimestampUnit.java line 226:
>
>> 225: public String getLocalizedDescription() {
>> 226: if (unitDescription == null) {
>> 227: String multiplier = timeOffsetUnit.asWellKnownQuantity().displayUsing(IDisplayable.EXACT);
>
> This makes this class thread unsafe, in the sense that there can be many local copies made of the unitDescription if used concurrently from multiple threads without any safety measures. Would an atomic reference be too expensive?
I did some more benchmarking, and using an AtomicReference is a bit faster than the previous lazy initialization.
-------------
PR: https://git.openjdk.java.net/jmc/pull/15
More information about the jmc-dev
mailing list