class SerialExecutor implements Executor {
final Queue<Runnable> tasks = new LinkedBlockingQueue<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
クラスは、拡張可能なスレッドプール実装を提供します。Executors
クラスは、これらの Executor 用の利便性の高いファクトリメソッドを提供します。
- 導入されたバージョン:
- 1.5
execute
void execute(Runnable command)
- 将来のある時点で指定されたコマンドを実行します。コマンドは、新規スレッド内でも、プールされたスレッド内でも、呼び出し側のスレッド内でも、Executor 実装により随意に実行できます。
- パラメータ:
command
- 実行可能なタスク
- 例外:
RejectedExecutionException
- タスクの実行を受け入れることができない場合
NullPointerException
- コマンドが null の場合
バグの報告と機能のリクエスト
さらに詳しい API リファレンスおよび開発者ドキュメントについては、Java 2 SDK SE 開発者用ドキュメントを参照してください。開発者向けの詳細な解説、概念の概要、用語の定義、バグの回避策、およびコード実例が含まれています。Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。