MANOOS~

블로그 이미지

grayhum

[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
Posted by grayhum
블로그 이미지

by grayhum

공지사항

    최근...

  • 포스트
  • 댓글
  • 트랙백
  • 더 보기

태그

글 보관함

«   2025/07   »
일 월 화 수 목 금 토
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

링크

카테고리

분류 전체보기 (16)
잡다 (1)
IT (15)
Spring (1)
jpa (0)
batch (0)
JAVA (5)
node&js (0)
ETC (1)
DB (0)
GO (7)
Clojure (0)
ELASTIC SEARCH (1)
MONGODB (0)
linux&mac (0)
Tensorflow (0)
bash (0)

카운터

Total
Today
Yesterday
방명록 : 관리자 : 글쓰기
grayhum's Blog is powered by daumkakao
Skin info material T Mark3 by 뭐하라
favicon

MANOOS~

  • 태그
  • 링크 추가
  • 방명록

관리자 메뉴

  • 관리자 모드
  • 글쓰기
  • 분류 전체보기 (16)
    • 잡다 (1)
    • IT (15)
      • Spring (1)
      • jpa (0)
      • batch (0)
      • JAVA (5)
      • node&js (0)
      • ETC (1)
      • DB (0)
      • GO (7)
      • Clojure (0)
      • ELASTIC SEARCH (1)
      • MONGODB (0)
      • linux&mac (0)
      • Tensorflow (0)
      • bash (0)

카테고리

PC화면 보기 티스토리 Daum

티스토리툴바