Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use monotonic clocks for SystemMonitor. #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 9 additions & 9 deletions jpos/src/main/java/org/jpos/q2/qbean/SystemMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
import java.net.InetAddress;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.time.zone.ZoneOffsetTransition;
import java.time.zone.ZoneOffsetTransitionRule;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
* Periodically dumps Thread and memory usage
Expand All @@ -55,8 +55,8 @@
public class SystemMonitor extends QBeanSupport
implements Runnable, SystemMonitorMBean, Loggeable
{
private long sleepTime = 60 * 60 * 1000;
private long delay = 0;
private Duration sleepTime = Duration.ofHours(1);
private Duration delay = Duration.ZERO;
private boolean detailRequired = false;
private Thread me = null;
private static final int MB = 1024*1024;
Expand All @@ -82,14 +82,14 @@ public void stopService() {
}

public synchronized void setSleepTime(long sleepTime) {
this.sleepTime = sleepTime;
this.sleepTime = Duration.ofMillis(sleepTime);
setModified(true);
if (me != null)
me.interrupt();
}

public synchronized long getSleepTime() {
return sleepTime;
return sleepTime.toMillis();
}

public synchronized void setDetailRequired(boolean detail) {
Expand Down Expand Up @@ -125,9 +125,9 @@ public void run() {
log.info(this);
frozenDump = null;
try {
long expected = System.currentTimeMillis() + sleepTime;
Thread.sleep(sleepTime);
delay = System.currentTimeMillis() - expected;
Duration expected = Duration.ofNanos(System.nanoTime()).plus(sleepTime);
Thread.sleep(sleepTime.toMillis());
delay = Duration.ofNanos(System.nanoTime()).minus(expected);
} catch (InterruptedException ignored) {
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ private String generateFrozenDump(String indent) {
Instant in = tran.getInstant();
p.printf("%s transition: %s (%s)%n", indent, in, in.atZone(zi));
}
p.printf("%s clock: %d %s%n", indent, System.currentTimeMillis() / 1000L, instant);
p.printf("%s clock: %d %s%n", indent, Instant.now().getEpochSecond(), instant);
if (hasSecurityManager())
p.printf("%s sec-manager: %s%n", indent, getSecurityManager());
p.printf("%s thread count: %d%n", indent, mxBean.getThreadCount());
Expand Down