Java TimeUnit Calculate randomSleep(int duration, TimeUnit timeUnit)

Here you can find the source of randomSleep(int duration, TimeUnit timeUnit)

Description

random Sleep

License

Apache License

Declaration

public static int randomSleep(int duration, TimeUnit timeUnit) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.google.common.base.Throwables;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

public class Main {
    public static int randomSleep(int duration, TimeUnit timeUnit) {
        int sleepTime = ThreadLocalRandom.current().nextInt(duration);
        try {/*from   w w  w  .java  2  s .c o  m*/
            timeUnit.sleep(sleepTime);
        } catch (InterruptedException e) {
            Throwables.propagate(e);
        }
        return sleepTime;
    }
}

Related

  1. minus(Date date, int interval, TimeUnit unit)
  2. parseTimeUnit(final String unit)
  3. parseTimeUnit(Object property, TimeUnit defaultValue)
  4. pause(long duration, TimeUnit unit)
  5. printTime(long time, TimeUnit unit)
  6. resetWithClockStep(long clockStep, TimeUnit clockStepUnit)
  7. run(final Runnable runnable, long timeout, TimeUnit unit)
  8. shortName(TimeUnit unit)
  9. sleep(int duration, TimeUnit unit)