Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.metrics.core;
 
An abstraction for how time passes. It is passed to Timer to track timing.
 
 public abstract class Clock {
    
Returns the current time tick.

Returns:
time tick in nanoseconds
    public abstract long tick();

    
Returns the current time in milliseconds.

Returns:
time in milliseconds
    public long time() {
        return System.currentTimeMillis();
    }
    private static final Clock DEFAULT = new UserTimeClock();

    
The default clock to use.

Returns:
the default Clock instance
See also:
Clock.UserTimeClock
    public static Clock defaultClock() {
        return ;
    }


    
A clock implementation which returns the current time in epoch nanoseconds.
    public static class UserTimeClock extends Clock {
        @Override
        public long tick() {
            return System.nanoTime();
        }
    }

    
A clock implementation which returns the current thread's CPU time.
    public static class CpuTimeClock extends Clock {
        private static final ThreadMXBean THREAD_MX_BEAN = ManagementFactory.getThreadMXBean();
        @Override
        public long tick() {
            return .getCurrentThreadCpuTime();
        }
    }
New to GrepCode? Check out our FAQ X