|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 전의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
| 개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 | |||||||||
public interface ScheduledExecutorService
지정된 지연 시간 후 또는 정기적으로 커멘드를 실행하도록(듯이) 스케줄 할 수 있는 ExecutorService 입니다.
schedule 메소드는, 다양한 지연의 설정된 태스크를 작성해, 실행의 취소해 또는 체크에 사용할 수 있는 태스크 객체를 돌려줍니다. scheduleAtFixedRate 메소드 및 scheduleWithFixedDelay 메소드는, 삭제될 때까지 정기적으로 실행되는 태스크를 작성 및 실행합니다.
Executor.execute(java.lang.Runnable) 및 ExecutorService 의 각 submit 메소드를 사용해 송신되는 커멘드는, 요구된 지연이 제로로서 스케줄 설정됩니다. schedule 메소드에서는 제로 또는 부의 지연 (기간은 제외하다)도 허가되어 그 경우는 즉시 실행하는 요구로서 다루어집니다.
모든 schedule 메소드는, 「상대적인」지연 및 기간을 인수로서 받아들입니다만, 절대 일시는 받아들이지 않습니다. Date 로서 나타내지는 절대 시간을 필요한 형식으로 변환하는 것은 간단합니다. 예를 들어 특정의 장래의 date 에 스케줄 설정하려면 ,schedule(task, date.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS) 를 사용할 수 있습니다. 다만 네트워크 시간 동기 프로토콜이나 클락의 차이등의 요인이 있기 (위해)때문에, 상대적인 지연의 유효기간 (태스크가 유효하게 되는 시점)이 현재의 Date 와 일치할 필요는 없습니다.
Executors 클래스는, 이 패키지로 제공되는 ScheduledExecutorService 구현으로 편리한 팩토리 메소드를 제공합니다.
import static java.util.concurrent.TimeUnit. *;
class BeeperControl {
private final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1);
public void beepForAnHour() {
final Runnable beeper = new Runnable() {
public void run() { System.out.println("beep"); }
};
final ScheduledFuture<? > beeperHandle =
scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
scheduler.schedule(new Runnable() {
public void run() { beeperHandle.cancel(true); }
}, 60 * 60, SECONDS);
}
}
| 메소드의 개요 | ||
|---|---|---|
|
schedule (Callable <V> callable,
long delay,
TimeUnit unit)
지정된 지연 후에 유효하게 되는 ScheduledFuture 를 작성해 실행합니다. |
|
ScheduledFuture <? > |
schedule (Runnable command,
long delay,
TimeUnit unit)
지정된 지연 후에 유효하게 되는 단발적인 액션을 작성해 실행합니다. |
|
ScheduledFuture <? > |
scheduleAtFixedRate (Runnable command,
long initialDelay,
long period,
TimeUnit unit)
지정된 초기 지연의 경과후에 처음 유효하게 되어, 그 후는 지정된 기간 마다 유효하게 되는 정기적인 액션을 작성해 실행합니다. |
|
ScheduledFuture <? > |
scheduleWithFixedDelay (Runnable command,
long initialDelay,
long delay,
TimeUnit unit)
지정된 초기 지연의 경과후에 처음 유효하게 되어, 그 후는 실행의 종료후부터 다음의 개시까지의 지정의 지연 마다 유효하게 되는 정기적인 액션을 작성해 실행합니다. |
|
| 인터페이스 java.util.concurrent. ExecutorService 로부터 상속된 메소드 |
|---|
awaitTermination , invokeAll , invokeAll , invokeAny , invokeAny , isShutdown , isTerminated , shutdown , shutdownNow , submit , submit , submit |
| 인터페이스 java.util.concurrent. Executor 로부터 상속된 메소드 |
|---|
execute |
| 메소드의 상세 |
|---|
ScheduledFuture <? > schedule(Runnable command,
long delay,
TimeUnit unit)
command - 실행하는 태스크delay - 현재부터 지연 실행까지의 시간unit - delay 파라미터의 시간 단위
RejectedExecutionException - 태스크의 실행을 스케줄 할 수 없는 경우
NullPointerException - 커멘드가 null 의 경우
<V> ScheduledFuture <V> schedule(Callable <V> callable,
long delay,
TimeUnit unit)
callable - 실행하는 함수delay - 현재부터 지연 실행까지의 시간unit - delay 파라미터의 시간 단위
RejectedExecutionException - 태스크의 실행을 스케줄 할 수 없는 경우
NullPointerException - 호출 가능 레이아웃이 null 의 경우
ScheduledFuture <? > scheduleAtFixedRate(Runnable command,
long initialDelay,
long period,
TimeUnit unit)
command - 실행하는 태스크initialDelay - 최초의 지연 실행까지의 시간period - 연속하는 실행의 간격unit - initialDelay 및 period 파라미터의 시간 단위
RejectedExecutionException - 태스크의 실행을 스케줄 할 수 없는 경우
NullPointerException - 커멘드가 null 의 경우
IllegalArgumentException - period 가 0 이하인 경우
ScheduledFuture <? > scheduleWithFixedDelay(Runnable command,
long initialDelay,
long delay,
TimeUnit unit)
command - 실행하는 태스크initialDelay - 최초의 지연 실행까지의 시간delay - 실행의 종료후부터 다음의 개시까지의 지연unit - initialDelay 및 delay 파라미터의 시간 단위
RejectedExecutionException - 태스크의 실행을 스케줄 할 수 없는 경우
NullPointerException - 커멘드가 null 의 경우
IllegalArgumentException - delay 가 0 이하인 경우
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 전의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
| 개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 | |||||||||
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.