Code example for TimeUnit

Methods: toNanos

0
    private final TimeUnit rateUnit;
    private final ScheduledFuture<?> future;
 
    public MeterMetric(ScheduledExecutorService tickThread, TimeUnit rateUnit) {
        this.rateUnit = rateUnit;
        this.future = tickThread.scheduleAtFixedRate(new Runnable() {
            @Override 
            public void run() { 
                tick(); 
            } 
        }, INTERVAL, INTERVAL, TimeUnit.SECONDS);
    } 
 
    public TimeUnit rateUnit() {
        return rateUnit;
    } 
 
    /** 
     * Updates the moving averages. 
     */ 
    void tick() { 
        m1Rate.tick();
        m5Rate.tick();
        m15Rate.tick();
    } 
 
    /** 
     * Mark the occurrence of an event. 
     */ 
    public void mark() { 
        mark(1); 
    } 
 
    /** 
     * Mark the occurrence of a given number of events. 
     * 
     * @param n the number of events 
     */ 
    public void mark(long n) {
        count.add(n);
        m1Rate.update(n);
        m5Rate.update(n);
        m15Rate.update(n);
    }