/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package org.apache.logging.log4j.core.helpers;

import java.util.concurrent.locks.LockSupport;

/**
 * Implementation of the {@code Clock} interface that tracks the time in a
 * private long field that is updated by a background thread once every
 * millisecond. Timers on most platforms do not have millisecond granularity, so
 * the returned value may "jump" every 10 or 16 milliseconds. To reduce this
 * problem, this class also updates the internal time value every 1024 calls to
 * {@code currentTimeMillis()}.
 */
public final class CachedClock implements Clock {
    private static final int UPDATE_THRESHOLD = 0x3FF;
    private static CachedClock instance = new CachedClock();
    private volatile long millis = System.currentTimeMillis();
    private volatile short count = 0;
    private final Thread updater = new Thread("Clock Updater Thread") {
        @Override
        public void run() {
            while (true) {
                final long time = System.currentTimeMillis();
                millis = time;

                // avoid explicit dependency on sun.misc.Util
                LockSupport.parkNanos(1000 * 1000);
            }
        }
    };

    private CachedClock() {
        updater.setDaemon(true);
        updater.start();
    }

    public static CachedClock instance() {
        return instance;
    }

    /**
     * Returns the value of a private long field that is updated by a background
     * thread once every millisecond. Timers on most platforms do not
     * have millisecond granularity, the returned value may "jump" every 10 or
     * 16 milliseconds. To reduce this problem, this method also updates the
     * internal time value every 1024 calls.
     * @return the cached time
     */
    @Override
    public long currentTimeMillis() {

        // improve granularity: also update time field every 1024 calls.
        // (the bit fiddling means we don't need to worry about overflows)
        if ((++count & UPDATE_THRESHOLD) == UPDATE_THRESHOLD) {
            millis = System.currentTimeMillis();
        }
        return millis;
    }
}

@@ -1582,16 +1582,17 @@
 nt = 0;%0A
+%0A
     priv
@@ -1595,16 +1595,40 @@
 private 
+CachedClock() %7B%0A        
 final Th
@@ -1657,30 +1657,21 @@
 ead(
-%22Clock Updater Thread%22
+new Runnable(
 ) %7B%0A
@@ -1674,24 +1674,28 @@
 ) %7B%0A        
+  
+  
 @Override%0A  
@@ -1688,24 +1688,28 @@
   @Override%0A
+    
         publ
@@ -1736,16 +1736,20 @@
         
+ 
+   
 while (t
@@ -1751,24 +1751,28 @@
 le (true) %7B%0A
+    
             
@@ -1829,32 +1829,36 @@
                 
+ 
+   
 millis = time;%0A%0A
@@ -1857,16 +1857,20 @@
  time;%0A%0A
+    
         
@@ -1939,16 +1939,20 @@
         
+ 
+   
 LockSupp
@@ -1983,34 +1983,42 @@
 0);%0A            
-%7D%0A
+    %7D%0A    
         %7D%0A    %7D;
@@ -2019,39 +2019,39 @@
     
-%7D;%0A%0A    private CachedClock() %7B
+    %7D, %22Clock Updater Thread%22);
 %0A   

Convert anonymous thread to runnable.