KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > concurrent > Executor


1 /*
2   File: Executor.java
3
4   Originally written by Doug Lea and released into the public domain.
5   This may be used for any purposes whatsoever without acknowledgment.
6   Thanks for the assistance and support of Sun Microsystems Labs,
7   and everyone contributing, testing, and using this code.
8
9   History:
10   Date Who What
11   19Jun1998 dl Create public version
12 */

13
14 package javax.concurrent;
15
16 /**
17  * Interface for objects that execute Runnables,
18  * as well as various objects that can be wrapped
19  * as Runnables.
20  * The main reason to use Executor throughout a program or
21  * subsystem is to provide flexibility: You can easily
22  * change from using thread-per-task to using pools or
23  * queuing, without needing to change most of your code that
24  * generates tasks.
25  * <p>
26  * The general intent is that execution be asynchronous,
27  * or at least independent of the caller. For example,
28  * one of the simplest implementations of <code>execute</code>
29  * (as performed in ThreadedExecutor)
30  * is <code>new Thread(command).start();</code>.
31  * However, this interface allows implementations that instead
32  * employ queueing or pooling, or perform additional
33  * bookkeeping.
34  * <p>
35  *
36  * <p>[<a HREF="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
37  **/

38 public interface Executor {
39   /**
40    * Execute the given command. This method is guaranteed
41    * only to arrange for execution, that may actually
42    * occur sometime later; for example in a new
43    * thread. However, in fully generic use, callers
44    * should be prepared for execution to occur in
45    * any fashion at all, including immediate direct
46    * execution.
47    * <p>
48    * The method is defined not to throw
49    * any checked exceptions during execution of the command. Generally,
50    * any problems encountered will be asynchronous and
51    * so must be dealt with via callbacks or error handler
52    * objects. If necessary, any context-dependent
53    * catastrophic errors encountered during
54    * actions that arrange for execution could be accompanied
55    * by throwing context-dependent unchecked exceptions.
56    * <p>
57    * However, the method does throw InterruptedException:
58    * It will fail to arrange for execution
59    * if the current thread is currently interrupted.
60    * Further, the general contract of the method is to avoid,
61    * suppress, or abort execution if interruption is detected
62    * in any controllable context surrounding execution.
63    **/

64   public void execute(Runnable JavaDoc command) throws InterruptedException JavaDoc;
65
66 }
67
Popular Tags