[9] RFR of 8069269: (spec) Defect in the System.nanoTime spec

Brian Burkhalter brian.burkhalter at oracle.com
Fri Jan 23 21:20:58 UTC 2015


On Jan 23, 2015, at 1:10 PM, Martin Buchholz <martinrb at google.com> wrote:

> We have struggled for years with formatting for code samples.  If you want to change it, get authoritative statement on how to do it with latest javadoc, publish it somewhere, and change it everywhere.  Putting the }</pre> on a line by itself did not produce the most readable output IIRC.

Any official guidance here would be welcome. I actually investigated the formatting style in other classes, e.g., AsynchronousServerSocketChannel, ServiceLoader, etc., and there is in fact a lack of consistency aside from the use of <pre></pre>. I did however build the docs before and after this change and the revised one looks better, at least on my system.

> ---
> 
> I don't see why switching t0 and t1 makes things more readable.

It’s about accuracy. The previous version is incorrect in the overflow case (if we even care).

> A real improvement might be: since one almost never compares two nanoTime values against each other, compare against "timeout" instead of against zero.  E.g.
> 
> long startTime = System.nanoTime();
> ...
> long elapsedNanos = System.nanoTime() - startTime;
> if (elapsedNanos < timeout) ...
> 
> using currently popular conventions in j.u.c.

That’s a thought …

Brian


More information about the core-libs-dev mailing list