Code example for TimeUnit

Methods: sleep

0
 
    private void doTask() throws InterruptedException { 
        Random random = new Random(new Date().getTime());
        int value = (int) (random.nextDouble() * 100);
        System.out.printf("Thread %s: %d\n", Thread.currentThread().getName(), value);
        TimeUnit.SECONDS.sleep(value);
    } 
 
}