View Javadoc
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 org.dbunit.util.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   * @author Doug Lea
39   * @author Last changed by: $Author$
40   * @version $Revision$ $Date$
41   * @since ? (pre 2.1)
42   */
43  public interface Executor {
44    /** 
45     * Execute the given command. This method is guaranteed
46     * only to arrange for execution, that may actually
47     * occur sometime later; for example in a new
48     * thread. However, in fully generic use, callers
49     * should be prepared for execution to occur in
50     * any fashion at all, including immediate direct
51     * execution.
52     * <p>
53     * The method is defined not to throw 
54     * any checked exceptions during execution of the command. Generally,
55     * any problems encountered will be asynchronous and
56     * so must be dealt with via callbacks or error handler
57     * objects. If necessary, any context-dependent 
58     * catastrophic errors encountered during
59     * actions that arrange for execution could be accompanied
60     * by throwing context-dependent unchecked exceptions.
61     * <p>
62     * However, the method does throw InterruptedException:
63     * It will fail to arrange for execution
64     * if the current thread is currently interrupted.
65     * Further, the general contract of the method is to avoid,
66     * suppress, or abort execution if interruption is detected
67     * in any controllable context surrounding execution.
68     **/
69    public void execute(Runnable command) throws InterruptedException;
70  
71  }