You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2015/03/22 21:15:11 UTC

[jira] [Comment Edited] (LOG4J2-982) Use System.nanoTime() to measure time intervals

    [ https://issues.apache.org/jira/browse/LOG4J2-982?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14375141#comment-14375141 ] 

Gary Gregory edited comment on LOG4J2-982 at 3/22/15 8:15 PM:
--------------------------------------------------------------

Here is something related http://bugs.java.com/view_bug.do?bug_id=6876279

Notice this:

{quote}
However due to historical (and continual) bugs in those OS time services the VM has evolved to add extra code - in particular for nanoTime ensuring that it is a monotonic non-decreasing time source as required.
{quote}

And this https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks

{quote}
You should always try to use nanoTime to do timing measurement or calculation (and yes there are JDK API's that don't do this), in the hope that it will have a better resolution than currentTimeMillis. 
{quote}


was (Author: garydgregory):
Here is something related http://bugs.java.com/view_bug.do?bug_id=6876279

Notice this:

{quote}
However due to historical (and continual) bugs in those OS time services the VM has evolved to add extra code - in particular for nanoTime ensuring that it is a monotonic non-decreasing time source as required.
{quote}

And this https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks

> Use System.nanoTime() to measure time intervals
> -----------------------------------------------
>
>                 Key: LOG4J2-982
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-982
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Core, Flume Appender
>            Reporter: Mikhail Mazurskiy
>            Priority: Minor
>         Attachments: LOG4J2-982.patch
>
>
> Unlike {{System.currentTimeMillis()}}, which can jump/slew forward and backwards, {{System.nanoTime()}} is a monotonic clock (at least it should be) and hence it should be used to measure time intervals (timeouts/delays/etc).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org