Skip to content

Instantly share code, notes, and snippets.

@harschware
Last active October 23, 2018 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harschware/6974b61837618574bae6ab75369ead30 to your computer and use it in GitHub Desktop.
Save harschware/6974b61837618574bae6ab75369ead30 to your computer and use it in GitHub Desktop.
Test NiFi StopWatch class - demonstrates bug at NIFI-5742
import org.apache.nifi.util.StopWatch;
import java.util.concurrent.TimeUnit;
class Scratch {
// https://github.com/apache/nifi/blob/02261311b3b3f765ebb394f8f101b0373a7fb3ab/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/StopWatch.java#L77
public static void main(String[] args) {
StopWatch stopWatch = new StopWatch(true);
try {
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
long millsSince = stopWatch.getElapsed(TimeUnit.MILLISECONDS);
System.out.println(millsSince);
try {
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
stopWatch.stop();
millsSince = stopWatch.getElapsed(TimeUnit.MILLISECONDS);
System.out.println(millsSince);
}
}
@harschware
Copy link
Author

The test class prints the following:

252
1897579286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment