-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWatcher.java
More file actions
35 lines (28 loc) · 1.26 KB
/
Watcher.java
File metadata and controls
35 lines (28 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Prints deltas each tick; exits on first backward step or after N samples.
public class Watcher {
public static void main(String[] args) throws Exception {
final long INTERVAL_MS = 1000;
final int SAMPLES = 30; // ~30s total
final long BACKWARD_THRESHOLD_MS = 2;
System.out.println("Java watcher: printing deltas; waiting for backward step...");
long prevWall = System.currentTimeMillis();
long prevMono = System.nanoTime();
for (int i = 0; i < SAMPLES; i++) {
Thread.sleep(INTERVAL_MS);
long nowWall = System.currentTimeMillis();
long nowMono = System.nanoTime();
long dWall = nowWall - prevWall;
long dMonoMs = (nowMono - prevMono) / 1_000_000L;
if (dWall < -BACKWARD_THRESHOLD_MS) {
System.out.printf("OK: wall BACKWARD %d ms | Δwall=%d ms, Δmono=%d ms. Exit.%n",
-dWall, dWall, dMonoMs);
System.exit(0);
}
System.out.printf("Δwall=%d ms, Δmono=%d ms%n", dWall, dMonoMs);
prevWall = nowWall;
prevMono = nowMono;
}
System.out.println("No backward step observed within samples. Exit(1).");
System.exit(1);
}
}