1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.jdiagnose.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 command) throws InterruptedException;
65
66 }