Sets an amount of time to call {@link DistributedQueue#flushPuts(long, TimeUnit)} when the
queue is closed. The default is 5 seconds. Pass 0 to turn flushing on close off.

@param time time
@param unit the unit
@return this
327067
public QueueBuilder<T>  finalFlushTime(int time, TimeUnit unit)
    {
        finalFlushMs = (int)unit.toMillis(time);
        return this;
    }
204408
public void setUnit(final String UNIT) {
        if (null == unit) {
            _unit = UNIT;
            fireTileEvent(VISIBILITY_EVENT);
            fireTileEvent(REDRAW_EVENT);
        } else {
            unit.set(UNIT);
        }
    }
878717
public V put(K key, V value, long timeout, TimeUnit unit)
    {
        if (lastPurge < System.currentTimeMillis())
        {
            size();
            lastPurge = System.currentTimeMillis() + purgeLimit;
        }
        V old = null;
        if (ttlSet.contains(key))
        {
            old = map.get(key);
        }
        map.put(key, value);
        if (unit == null)
        {
            ttlSet.add(key);
        }
        else
        {
            ttlSet.add(key, timeout, unit);
        }
        return old;
    }
1044057
public Retryer<R> fixedWait(long sleepTime, TimeUnit timeUnit) {
        withWaitStrategy(fixedWaitStrategy(checkNotNull(timeUnit, "TimeUnit cannot be null").toMillis(sleepTime)));
        return this;
    }
951098
public void enqueueWork(AsyncUpdate unit) throws ClosedException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "enqueueWork", unit);

    synchronized (this)
    {
      if (closed)
      {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
          SibTr.exit(tc, "enqueueWork", "ClosedException");
        throw new ClosedException();
      }
      
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
        SibTr.debug(tc, "Enqueueing update: " + unit);
      
      enqueuedUnits.add(unit);
      if (executing)
      {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
          SibTr.exit(tc, "enqueueWork", "AsyncUpdateThread executing");
        return;
      }

      // not executing enqueued updates
      if (enqueuedUnits.size() > batchThreshold)
      {
        executeSinceExpiry = true;
        try
        {
          startExecutingUpdates();
        }
        catch (ClosedException e)
        {
          // No FFDC code needed
          if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "enqueueWork", e);
          throw e;
        }
      }
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "enqueueWork");
  }
793366
public T setDuration(long duration, TimeUnit units) {
    checkNotNull(units);

    this.duration = units.toMillis(duration);

    return getThis();
  }
891914
public static void sleep(long time, TimeUnit unit) {
        try {
            if (time <= 0 || unit == null) {
                return;
            }

            Thread.sleep(unit.toMillis(time));
        } catch (InterruptedException e) {
            log.warn("时间参数不正确或者线程被中断，线程将不会睡眠");
            throw new RuntimeException(e);
        }
    }
1274241
private void flushSinkAtInterval() {
    Object flushIntervalObj = sinkConfig.get(MetricsSinksConfig.CONFIG_KEY_FLUSH_FREQUENCY_MS);

    // If the config is not set, we consider the flush() would never be invoked
    if (flushIntervalObj != null) {
      final Duration flushInterval = TypeUtils.getDuration(flushIntervalObj, ChronoUnit.MILLIS);

      Runnable flushSink = new Runnable() {
        @Override
        public void run() {
          metricsSink.flush();
          //Plan itself in future
          slaveLooper.registerTimerEvent(flushInterval, this);
        }
      };

      // Plan the runnable explicitly at the first time
      slaveLooper.registerTimerEvent(flushInterval, flushSink);
    }
  }
1209577
public static void updateTimer(Optional<Timer> timer, final long duration, final TimeUnit unit) {
    timer.transform(new Function<Timer, Timer>() {
      @Override
      public Timer apply(@Nonnull Timer input) {
        input.update(duration, unit);
        return input;
      }
    });
  }
1109773
public AdjustableClock withOffset(
        int offset,
        TimeUnit unit
    ) {

        if (unit == null) {
            throw new NullPointerException("Missing offset unit.");
        } else if (
            (this.offsetAmount == offset)
            && (this.offsetUnit == unit)
        ) {
            return this;
        }

        return new AdjustableClock(
            this.source,
            this.pulse,
            offset,
            unit);

    }
974361
public PollingWait pollEvery(long timeAmount, @Nonnull TimeUnit timeUnit) {
        if (timeAmount <= 0) {
            throw new IllegalArgumentException("Invalid timeAmount: " + timeAmount + " -- must be greater than 0");
        }
        pollIntervalMillis = timeUnit.toMillis(timeAmount);
        return this;
    }
988190
public PollingWait timeoutAfter(long timeAmount, @Nonnull TimeUnit timeUnit) {
        if (timeAmount <= 0) {
            throw new IllegalArgumentException("Invalid timeAmount: " + timeAmount + " -- must be greater than 0");
        }
        timeoutMillis = timeUnit.toMillis(timeAmount);
        return this;
    }
1125960
public void setRetention(long duration, TimeUnit timeUnit) {
        this._duration = Math.max(1, duration);
        this._timeUnit = timeUnit;
        
        long millis = TimeUnit.MILLISECONDS == timeUnit ?
                _duration : TimeUnit.MILLISECONDS.convert(_duration, timeUnit);
        _timeMillis = Math.max(millis, MIN_DURATION_MILLIS);
    }
305189
public static long millis(final String time, final String timeUnit) {
      return TIMEUNITS.get(timeUnit).toMillis(Long.parseLong(time));
   }
504890
protected void processUnit (Object unit)
    {
        long start = System.nanoTime();

        // keep track of the largest queue size we've seen
        int queueSize = _evqueue.size();
        if (queueSize > _current.maxQueueSize) {
            _current.maxQueueSize = queueSize;
        }

        try {
            if (unit instanceof Runnable) {
                // if this is a runnable, it's just an executable unit that should be invoked
                ((Runnable)unit).run();

            } else {
                DEvent event = (DEvent)unit;

                // if this event is on a proxied object, forward it to the owning manager
                ProxyReference proxy = _proxies.get(event.getTargetOid());
                if (proxy != null) {
                    // rewrite the oid into the originating manager's id space
                    event.setTargetOid(proxy.origObjectId);
                    // then pass it on to the originating manager to handle
                    proxy.origManager.postEvent(event);

                } else if (event instanceof CompoundEvent) {
                    processCompoundEvent((CompoundEvent)event);

                } else {
                    processEvent(event);
                }
            }

        } catch (VirtualMachineError e) {
            handleFatalError(unit, e);

        } catch (Throwable t) {
            log.warning("Execution unit failed", "unit", unit, t);
        }

        // compute the elapsed time in microseconds
        long elapsed = (System.nanoTime() - start)/1000;

        // report excessively long units
        if (elapsed > 500000 && !(unit instanceof LongRunnable)) {
            log.warning("Long dobj unit " + StringUtil.shortClassName(unit), "unit", unit,
                        "time", (elapsed/1000) + "ms");
        }

        // periodically sample and record the time spent processing a unit
        if (UNIT_PROF_ENABLED && _eventCount % _unitProfInterval == 0) {
            String cname;
            // do some jiggery pokery to get more fine grained profiling details on certain
            // "popular" unit types
            if (unit instanceof Interval.RunBuddy) {
                cname = StringUtil.shortClassName(
                    ((Interval.RunBuddy)unit).getIntervalClassName());
            } else if (unit instanceof InvocationRequestEvent) {
                InvocationRequestEvent ire = (InvocationRequestEvent)unit;
                Class<?> c = _invmgr.getDispatcherClass(ire.getInvCode());
                cname = (c == null) ? "dobj.InvocationRequestEvent:(no longer registered)" :
                    StringUtil.shortClassName(c) + ":" + ire.getMethodId();
            } else {
                cname = StringUtil.shortClassName(unit);
            }
            UnitProfile uprof = _profiles.get(cname);
            if (uprof == null) {
                _profiles.put(cname, uprof = new UnitProfile());
            }
            uprof.record(elapsed);
        }
    }
297205
public void flush() throws IOException {
        if (unflushed.get() == 0) return;

        synchronized (lock) {
            if (logger.isTraceEnabled()) {
                logger.debug("Flushing log '" + name + "' last flushed: " + getLastFlushedTime() + " current time: " + System
                        .currentTimeMillis());
            }
            segments.getLastView().getMessageSet().flush();
            unflushed.set(0);
            lastflushedTime.set(System.currentTimeMillis());
        }
    }
941706
public LogWatchBuilder withDelayBetweenReads(final int length, final TimeUnit unit) {
        this.delayBetweenReads = LogWatchBuilder.getDelay(length, unit);
        return this;
    }