삶 가운데 남긴 기록 AACII.TISTORY.COM
JAVA 스레드 없이 지연 sleep() 시키기 본문
java.util.concurrent.TimeUnit 패키지
TimeUnit은 멀티 Thread가 아닌 메서드에서 시간을 지연 시킬 때 사용합니다.
예제
import java.util.concurrent.TimeUnit;
public class SimpleTest {
public static void main(String[] args) {
try {
for (int i = 0; i < 3; i++) {
TimeUnit.SECONDS.sleep(2);
System.out.println("Sleep "+i+" sec");
}
}catch(Exception e) {
System.out.println(e);
}
}
}
자세한 api 문서는 아래 참고
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html
TimeUnit (Java Platform SE 7 )
Convert the given time duration in the given unit to this unit. Conversions from finer to coarser granularities truncate, so lose precision. For example converting 999 milliseconds to seconds results in 0. Conversions from coarser to finer granularities wi
docs.oracle.com
끗.
728x90
'DEV&OPS > Java' 카테고리의 다른 글
JAVA 콘솔 application 리눅스 실행 시 참고 사항 (0) | 2022.11.07 |
---|---|
JAVA 코딩 컨벤션 (0) | 2022.10.20 |
Spring boot todo - REST API Service (0) | 2022.08.31 |
Spring boot todo - REST API Controller (0) | 2022.08.31 |
Spring boot todo - Model, Entity, DTO (0) | 2022.08.30 |