[JAVA] TimeUnit.Sleep vs Thread.Sleep
IT/JAVA
2015. 12. 23. 22:56
결론부터 말하자면 어차피 그놈이 그놈...
TimeUnit.Second.Sleep() 소스 까보면 다음과 같다.
/**
* Performs a {@link Thread#sleep(long, int) Thread.sleep} using
* this time unit.
* This is a convenience method that converts time arguments into the
* form required by the {@code Thread.sleep} method.
*
* @param timeout the minimum time to sleep. If less than
* or equal to zero, do not sleep at all.
* @throws InterruptedException if interrupted while sleeping
*/
public void sleep(long timeout) throws InterruptedException {
if (timeout > 0) {
long ms = toMillis(timeout);
int ns = excessNanos(timeout, ms);
Thread.sleep(ms, ns);
}
}
TimeUnit의 static method가 직관적인게 장점!
5분 딜레이 줄때
Thread.Sleep(5 * 60 * 1000);
보다
TimeUnit.MINUTES.Sleep(5);
가 보기 편하니까.
'IT > JAVA' 카테고리의 다른 글
JAVA 8 연습 - 피타고라스 숫자 추출. (0) | 2016.07.09 |
---|---|
[JAVA] 메소드에서 클래스 선언이 될까? (0) | 2016.01.07 |
leftPad 구현 (0) | 2015.11.30 |
fffd (0) | 2015.11.30 |