TimeUnit.SECONDS.sleep(x)会打电话给
Thread.sleep。唯一的区别是可读性,
TimeUnit在不明显的持续时间内使用(例如:
Thread.sleep(180000)vs
TimeUnit.MINUTES.sleep(3).)可能更容易理解。
供参考,请参见以下
sleep()in 中的代码
TimeUnit:
public void sleep(long timeout) throws InterruptedException { if (timeout > 0) { long ms = toMillis(timeout); int ns = excessNanos(timeout, ms); Thread.sleep(ms, ns); }}


