logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: svn commit: r1595736 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CoarseCachedClock.java
Date Mon, 19 May 2014 03:45:05 GMT
Matt,

Sorry, I didn't get that. What is the problem with a plain volatile long?

This class is a bit performance sensitive: it can be used instead of the system clock to squeeze
the last drop of performance out of async logging, in return for less precision. 
Did you verify that this implementation is just as fast?

Regards,
Remko

Sent from my iPhone

> On 2014/05/19, at 12:18, mattsicker@apache.org wrote:
> 
> Author: mattsicker
> Date: Mon May 19 03:18:09 2014
> New Revision: 1595736
> 
> URL: http://svn.apache.org/r1595736
> Log:
> Use AtomicLong over volatile long due to problematic implementations of volatile long.
> 
> Modified:
>    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CoarseCachedClock.java
> 
> Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CoarseCachedClock.java
> URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CoarseCachedClock.java?rev=1595736&r1=1595735&r2=1595736&view=diff
> ==============================================================================
> --- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CoarseCachedClock.java
(original)
> +++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CoarseCachedClock.java
Mon May 19 03:18:09 2014
> @@ -16,6 +16,7 @@
>  */
> package org.apache.logging.log4j.core.util;
> 
> +import java.util.concurrent.atomic.AtomicLong;
> import java.util.concurrent.locks.LockSupport;
> 
> /**
> @@ -24,14 +25,13 @@ import java.util.concurrent.locks.LockSu
>  */
> public final class CoarseCachedClock implements Clock {
>     private static final CoarseCachedClock instance = new CoarseCachedClock();
> -    private volatile long millis = System.currentTimeMillis();
> +    private final AtomicLong millis = new AtomicLong(System.currentTimeMillis());
> 
>     private final Thread updater = new Thread("Clock Updater Thread") {
>         @Override
>         public void run() {
>             while (true) {
> -                final long time = System.currentTimeMillis();
> -                millis = time;
> +                millis.set(System.currentTimeMillis());
> 
>                 // avoid explicit dependency on sun.misc.Util
>                 LockSupport.parkNanos(1000 * 1000);
> @@ -62,6 +62,6 @@ public final class CoarseCachedClock imp
>      */
>     @Override
>     public long currentTimeMillis() {
> -        return millis;
> +        return millis.get();
>     }
> }
> 
> 

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


Mime
View raw message