@@ -42,47 +42,44 @@ public class SpyingTask implements Runnable {
4242 private final Integer scheduledSequenceIndex ;
4343 private String runThreadName ;
4444 private long runThreadId ;
45- private long runTimeEndMillis ;
46- private long runTimeStartMillis ;
45+ private long runTimeEndNanos ;
46+ private long runTimeStartNanos ;
4747
4848 public SpyingTask (Integer scheduledSequenceIndex ) {
4949 this .scheduledSequenceIndex = scheduledSequenceIndex ;
5050 reset ();
5151 }
5252
53- public Duration getActualRunDuration () {
53+ private Duration getActualRunDuration () {
5454 if (!isDone ()) {
5555 throw new IllegalStateException ("actual run duration not available until run completes" );
5656 }
57- return Duration .ofMillis (this .runTimeEndMillis - this .runTimeStartMillis );
57+ return Duration .ofNanos (this .runTimeEndNanos - this .runTimeStartNanos );
5858 }
5959
6060 public boolean isDone () {
61- return this .runTimeStartMillis != UNSET_TIME_STAMP && this .runTimeEndMillis != UNSET_TIME_STAMP ;
61+ return this .runTimeStartNanos != UNSET_TIME_STAMP && this .runTimeEndNanos != UNSET_TIME_STAMP ;
6262 }
6363
6464 @ Override
6565 public void run () {
6666 reset ();
67- this .runTimeStartMillis = System .nanoTime ();
67+ this .runTimeStartNanos = System .nanoTime ();
6868 this .runThreadName = Thread .currentThread ().getName ();
6969 this .runThreadId = Thread .currentThread ().threadId ();
7070 await ()
7171 .with ()
7272 .pollInterval (POLL_INTERVAL )
73- .until (() -> (System .nanoTime () - this .runTimeStartMillis ) >= RUN_DURATION_MILLIS );
74- this .runTimeEndMillis = System .nanoTime ();
73+ .until (() -> (System .nanoTime () - this .runTimeStartNanos ) >= RUN_DURATION_MILLIS );
74+ this .runTimeEndNanos = System .nanoTime ();
7575 System .out .printf (
7676 "Task %s run by %s:%s completed in %s%n" ,
77- scheduledSequenceIndex ,
78- runThreadName ,
79- runThreadId ,
80- Duration .ofNanos (runTimeEndMillis - runTimeStartMillis ));
77+ scheduledSequenceIndex , runThreadName , runThreadId , getActualRunDuration ());
8178 }
8279
8380 private void reset () {
84- this .runTimeStartMillis = UNSET_TIME_STAMP ;
85- this .runTimeEndMillis = UNSET_TIME_STAMP ;
81+ this .runTimeStartNanos = UNSET_TIME_STAMP ;
82+ this .runTimeEndNanos = UNSET_TIME_STAMP ;
8683 this .runThreadName = null ;
8784 this .runThreadId = UNSET_THREAD_ID ;
8885 }
0 commit comments