Here you can find the source of deepSleep(long sleepFor, TimeUnit unit)
Parameter | Description |
---|---|
nanos | a parameter |
public final static void deepSleep(long sleepFor, TimeUnit unit)
//package com.java2s; //License from project: Apache License import java.util.concurrent.TimeUnit; public class Main { /**/* w w w .j av a 2 s . c o m*/ * sleep until timeout. * * @param nanos */ public final static void deepSleep(long sleepFor, TimeUnit unit) { if (sleepFor < 0) { throw new IllegalArgumentException("sleepFor can't be minus."); } long startTimeInNanos = System.nanoTime(); long leftNanos = unit.toNanos(sleepFor); boolean isInterrupted = false; while (leftNanos > 0) { try { TimeUnit.NANOSECONDS.sleep(leftNanos); leftNanos = 0; } catch (InterruptedException e) { isInterrupted = true; leftNanos -= (System.nanoTime() - startTimeInNanos); } } if (isInterrupted) { Thread.currentThread().interrupt(); } } }