[concurrency-interest] java.lang.System.nanoTime and QueryPerformanceCounter-"Bug"

David Holmes dholmes@dltech.com.au
Wed, 24 Dec 2003 12:44:35 +1000


Michael,

> With every call to System.nanoTime() you compare its
> results with the results of millisecond-accurate Time

If an implementation knew that there were problems using the
underlying platform timing facilities then it would indeed have to
resort to something like this. Hopefully use of the TSC will avoid
such problems.

> This way you can determine if a leap has occured and in this case
return the
> millisecond accurate time (which is IMHO better than to return the
nanosecond
> accurate time plus leap seconds). But you should give the developer
a hint
> that this result may have only one millisecond accuracy and not just
silently
> provide him with a result with accuracy LessThanNano when he expects
nano
> accuracy because of the name of the method.

System.nanoTime is not required to have nanosecond accuracy only
nanosecond precision. An implementation that returned
currentTimeMillis()*1000000 would be a correct though low-quality
implementation. An implementation should document the accuracy of
nanoTime.

David Holmes