Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class SystemResourcesCounter extends Thread {

private volatile boolean running = true;

private long[] previousCpuTicks;
private long[][] previousProcCpuTicks;
private volatile long[] previousCpuTicks;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at the usages of these 2 fields
it seems previousCpuTicks is only updated if it is null. Which looks very strange - is this right? I can see that volatile could be useful here if this is correct processing.

previousProcCpuTicks is updated when null then after processing in the method see code here. I wonder if the
previousCpuTicks logic should update it, in the same way as previousProcCpuTicks .

I was looking at these usages to see if AtomicReference should be used rather than volatile. This would be more thread safe, and to use compareAndSet() to update it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that it is also the only place it can be initialized.

I agree with AtomicRefrence, I was thinking about the same thing. Should I add an commit with that? :)

private volatile long[][] previousProcCpuTicks;
private long[] bytesReceivedPerInterface;
private long[] bytesSentPerInterface;

Expand Down