|
JavaTM Platform Standard Ed. 6 |
|||||||||
앞의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 열거형 정수 | 필드 | 메소드 | 상세 : 열거형 정수 | 필드 | 메소드 |
java.lang.Objectjava.lang.Enum <TimeUnit >
java.util.concurrent.TimeUnit
public enum TimeUnit
TimeUnit 는, 지정된 입도 단위로 시간을 나타내, 단위를 변환하거나 그러한 단위로 타이밍 및 지연 조작을 실행하거나 하는 유틸리티 메소드를 제공합니다. TimeUnit 는, 시간 정보를 보관 유지하지 않고, 다양한 문맥간에 독립해 보관 유지되는 시간표현의 정리 및 사용만을 실시할 수가 있습니다. 나노초는 마이크로 세컨드의 1000 분의 1, 마이크로 세컨드는 밀리 세컨드의 1000 분의 1, 밀리 세컨드는 초의 1000 분의 1, 분은 60 초, 때는 60 분 , 날은 24 시간으로서 각각 정의됩니다.
TimeUnit 는, 주로 시간 베이스의 메소드에 대해서, 지정된 타이밍 파라미터의 해석 방법을 지시하기 위해서 사용합니다. 예를 들어 다음의 코드는,락
을 이용할 수 없는 경우, 50 밀리 세컨드로 타임 아웃 합니다.
Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...한편, 다음의 코드는, 50 초에 타임 아웃 합니다.
Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...다만, 특정의 타임 아웃 구현으로, 지정된 TimeUnit 와 같은 입도로 시간 경과를 통지할 수 있는 보증은 없습니다.
열거형 정수의 개요 | |
---|---|
DAYS
|
|
HOURS
|
|
MICROSECONDS
|
|
MILLISECONDS
|
|
MINUTES
|
|
NANOSECONDS
|
|
SECONDS
|
메소드의 개요 | |
---|---|
long |
convert (long sourceDuration,
TimeUnit sourceUnit)
지정된 단위에 의한 지정된 시간을, 이 단위로 변환합니다. |
void |
sleep (long timeout)
이 단위를 사용해 Thread.sleep 를 실행합니다. |
void |
timedJoin (Thread thread,
long timeout)
이 시간 단위를 사용해, 시간 지정된 Thread.join 를 실행합니다. |
void |
timedWait (Object obj,
long timeout)
이 시간 단위를 사용해, 시간 지정된 Object.wait 를 실행합니다. |
long |
toDays (long duration)
DAYS.convert(duration, this) 와 동등합니다. |
long |
toHours (long duration)
HOURS.convert(duration, this) 와 동등합니다. |
long |
toMicros (long duration)
MICROSECONDS.convert(duration, this) 와 동등합니다. |
long |
toMillis (long duration)
MILLISECONDS.convert(duration, this) 와 동등합니다. |
long |
toMinutes (long duration)
MINUTES.convert(duration, this) 와 동등합니다. |
long |
toNanos (long duration)
NANOSECONDS.convert(duration, this) 와 동등합니다. |
long |
toSeconds (long duration)
SECONDS.convert(duration, this) 와 동등합니다. |
static TimeUnit |
valueOf (String name)
지정한 이름을 가지는 이 형태의 열거형 정수를 돌려줍니다. |
static TimeUnit [] |
values ()
이 열거형의 정수를 포함한 배열이 선언되고 있는 순서로 돌려줍니다. |
클래스 java.lang. Enum 로부터 상속된 메소드 |
---|
clone , compareTo , equals , finalize , getDeclaringClass , hashCode , name , ordinal , toString , valueOf |
클래스 java.lang. Object 로부터 상속된 메소드 |
---|
getClass , notify , notifyAll , wait , wait , wait |
열거형 정수의 상세 |
---|
public static final TimeUnit NANOSECONDS
public static final TimeUnit MICROSECONDS
public static final TimeUnit MILLISECONDS
public static final TimeUnit SECONDS
public static final TimeUnit MINUTES
public static final TimeUnit HOURS
public static final TimeUnit DAYS
메소드의 상세 |
---|
public static TimeUnit [] values()
for (TimeUnit c : TimeUnit.values()) System.out.println(c);
public static TimeUnit valueOf(String name)
name
- 반환되는 열거형 정수의 이름
IllegalArgumentException
- 지정된 이름을 가지는 정수를
이 열거형이 가지고 있지 않은 경우
NullPointerException
- 인수가 null 의 경우public long convert(long sourceDuration, TimeUnit sourceUnit)
예를 들어 10 분을 밀리 세컨드 단위로 변환하려면 ,TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES) 를 사용합니다.
sourceDuration
- 지정된 sourceUnit 에서의 시간sourceUnit
- sourceDuration 인수의 단위
public long toNanos(long duration)
duration
- 시간
convert(long, java.util.concurrent.TimeUnit)
public long toMicros(long duration)
duration
- 시간
convert(long, java.util.concurrent.TimeUnit)
public long toMillis(long duration)
duration
- 시간
convert(long, java.util.concurrent.TimeUnit)
public long toSeconds(long duration)
duration
- 시간
convert(long, java.util.concurrent.TimeUnit)
public long toMinutes(long duration)
duration
- 시간
convert(long, java.util.concurrent.TimeUnit)
public long toHours(long duration)
duration
- 시간
convert(long, java.util.concurrent.TimeUnit)
public long toDays(long duration)
duration
- 시간
convert(long, java.util.concurrent.TimeUnit)
public void timedWait(Object obj, long timeout) throws InterruptedException
예를 들어 다음과 같이 해, 블록 하는 poll 메소드를 구현할 수 있습니다 (BlockingQueue.poll
를 참조).
public synchronized Object poll(long timeout, TimeUnit unit) throws InterruptedException { while (empty) { unit.timedWait(this, timeout); ... } }
obj
- 대기하는 객체timeout
- 대기하는 최장 시간. 제로 또는 그것보다 작은 경우는 대기하지 않는다
InterruptedException
- 대기중에 인터럽트가 발생했을 경우Object.wait(long, int)
public void timedJoin(Thread thread, long timeout) throws InterruptedException
thread
- 대기하는 threadtimeout
- 대기하는 최장 시간. 제로 또는 그것보다 작은 경우는 대기하지 않는다
InterruptedException
- 대기중에 인터럽트가 발생했을 경우Thread.join(long, int)
public void sleep(long timeout) throws InterruptedException
timeout
- sleeve 하는 최소 시간. 제로 또는 그것보다 작은 경우는 sleeve 하지 않는다
InterruptedException
- sleeve중에 인터럽트가 발생했을 경우Thread.sleep(long)
|
JavaTM Platform Standard Ed. 6 |
|||||||||
앞의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 열거형 정수 | 필드 | 메소드 | 상세 : 열거형 정수 | 필드 | 메소드 |
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.