|
JavaTM Platform Standard Ed. 6 |
|||||||||
앞의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
public interface Executor
송신된 Runnable
태스크를 실행하는 객체입니다. 이 인터페이스는, 태스크 송신을 각 태스크의 실행 방식 (thread의 사용이나 스케줄링의 상세등을 포함한다)으로부터 분리하는 방법을 제공합니다. 일반적으로,executor 는, 명시적으로 thread를 작성하는 대신에 사용됩니다. 예를 들어, task set 마다 new Thread(new(RunnableTask())). start() 를 호출하는 대신에, 이하를 사용할 수 있습니다.
Executor executor = anExecutor; executor.execute(new RunnableTask1()); executor.execute(new RunnableTask2()); ...다만,executor 인터페이스에서는, 실행이 비동기인 것이 엄밀하게 요구되는 것은 아닙니다. 무엇보다 단순한 케이스에서는, executor 는, 송신된 태스크를 호출해 옆의 thread내에서 즉시 실행할 수 있습니다.
class DirectExecutor implements Executor { public void execute(Runnable r) { r.run(); } }보다 일반적으로는, 태스크는 호출해 옆의 thread 이외의 thread로 실행됩니다. 다음에 나타내는 executor 는, 각 태스크용의 신규 thread를 생성합니다.
class ThreadPerTaskExecutor implements Executor { public void execute(Runnable r) { new Thread(r). start(); } }다수의 executor 구현은, 태스크를 스케줄 하는 방법 및 시기에 관해서 어떠한 제한을 부과합니다. 다음에, executor 가 태스크의 송신을 직렬화해 2 번째의 executor 에 건네주는, 복합 executor 를 나타냅니다.
class SerialExecutor implements Executor { final Queue<Runnable> tasks = new ArrayDeque<Runnable>(); final Executor executor; Runnable active; SerialExecutor(Executor executor) { this.executor = executor; } public synchronized void execute(final Runnable r) { tasks.offer(new Runnable() { public void run() { try { r.run(); } finally { scheduleNext(); } } }); if (active == null) { scheduleNext(); } } protected synchronized void scheduleNext() { if ((active = tasks.poll()) ! = null) { executor.execute(active); } } }이 패키지로 제공되는 Executor 구현은, 보다 확장성의 높은 인터페이스인
ExecutorService
를 구현합니다. ThreadPoolExecutor
클래스는, 확장 가능한 thread 풀 구현을 제공합니다. Executor
클래스는, 이러한 Executor 용의 편리성의 높은 팩토리 메소드를 제공합니다.
메모리 무결성 효과:Runnable
객체를 Executor
에 송신하기 전의 thread내의 액션은, 다른 thread로 행해질 가능성이 있는 실행의 개시보다 happen-before 입니다.
메소드의 개요 | |
---|---|
void |
execute (Runnable command)
장래의 어느 시점인가로, 지정된 커멘드를 실행합니다. |
메소드의 상세 |
---|
void execute(Runnable command)
command
- 실행 가능한 태스크
RejectedExecutionException
- 태스크의 실행을 받아들일 수가 없는 경우
NullPointerException
- 커멘드가 null 의 경우
|
JavaTM Platform Standard Ed. 6 |
|||||||||
앞의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.