GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — Avoid usage of the non monotonic clock System.currentTimeMillis() in favor of System.nanoTime() by Nateckert · Pull Request #6392 · testcontainers/testcontainers-java ConversationIn Java, long start = System.currentTimeMillis(); ... long end = System.currentTimeMillis(); System.println.out(end - start); might print a number smaller than zero ! This is due to the fact that the internal clock of computer if not accurate and it is put back on the "right" time thanks to the UDP protocol. Additional read: https://superuser.com/questions/759730/how-much-clock-drift-is-considered-normal-for-a-non-networked-windows-7-pc Instead,
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Thanks for providing a PR @Nateckert. Is this an issue you have observed in your system while using Testcontainers? Could you please run |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I ran the formatter. I actually don't know if we encounter that issue, but we are currently trying to sanitize our CI and this was a quick fix to a unlikely problem that can be almost impossible to debug (looks random, there is no associated logs, ...), so that's why I wanted to contribute |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| private void waitUntil(Predicate<OutputFrame> predicate, long expiry, int times) throws TimeoutException { | ||
| int numberOfMatches = 0; | ||
| while (System.currentTimeMillis() < expiry) { | ||
| while (System.nanoTime() < expiry) { |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nanoTime is subject to overflow/wrapping and the addition of an offset may have wrapped.
Whilst this could have happened with mills you wouldn't care for a few more years. nanoTime is relative to a random point in time so it could be a very large number or a very small number, positive or megative
As per javadoc
To compare two nanoTime values
long t0 = System.nanoTime();
...
long t1 = System.nanoTime();
one should use t1 - t0 < 0, not t1 < t0, because of the possibility of numerical overflow.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
With the changes after @jtnord's feedback, I managed to update the estimate |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for your contribution, @Nateckert ! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…favor of System.nanoTime() (testcontainers#6392) Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.