RFR: 8297173: usageTicks and totalTicks should be volatile to ensure that different threads get the latest ticks

Alan Bateman alanb at openjdk.org
Thu Nov 17 09:37:23 UTC 2022


On Thu, 17 Nov 2022 06:28:37 GMT, Poison <duke at openjdk.org> wrote:

> As the title says, add the volatile modifier.

src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java line 53:

> 51:     private abstract class ContainerCpuTicks {
> 52:         private volatile long usageTicks = 0;
> 53:         private volatile long totalTicks = 0;

You can drop initialising the fields to 0 (their default value) while you are at it as they are volatile writes.

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

PR: https://git.openjdk.org/jdk/pull/11199


More information about the serviceability-dev mailing list