ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/Future.java
Revision: 1.10
Committed: Sun Aug 24 14:47:31 2003 UTC (20 years, 9 months ago) by dl
Branch: MAIN
Changes since 1.9: +12 -2 lines
Log Message:
Javadoc clarifications

File Contents

# Content
1 /*
2 * @(#)Future.java
3 */
4
5 package java.util.concurrent;
6
7 /**
8 * A <tt>Future</tt> represents the result of an asynchronous computation.
9 * Methods are provided to check if the computation is complete,
10 * to wait for its completion, and to retrieve the result of the
11 * computation. The result can only be retrieved when the computation
12 * has completed. The <tt>get</tt> method will block until the computation
13 * has completed. Once the computation has completed, the result cannot
14 * be changed, nor can the computation be restarted or cancelled.
15 *
16 * <p>
17 * <b>Sample Usage</b> (Note that the following classes are all
18 * made-up.) <p>
19 * <pre>
20 * interface ArchiveSearcher { String search(String target); }
21 * class App {
22 * Executor executor = ...
23 * ArchiveSearcher searcher = ...
24 * void showSearch(final String target) throws InterruptedException {
25 * Future&lt;String&gt; future =
26 * new FutureTask&lt;String&gt;(new Callable&lt;String&gt;() {
27 * public String call() {
28 * return searcher.search(target);
29 * }});
30 * executor.execute(future);
31 * displayOtherThings(); // do other things while searching
32 * try {
33 * displayText(future.get()); // use future
34 * } catch (ExecutionException ex) { cleanup(); return; }
35 * }
36 * }
37 * </pre>
38 *
39 * The {@link Executors} class contains more convenient methods
40 * for common usages. For example, the above explicit
41 * construction could be replaced with:
42 * <pre>
43 * Future&lt;String&gt; future = Executors.execute(executor,
44 * new Callable&lt;String&gt;() {
45 * public String call() {
46 * return searcher.search(target);
47 * }});
48 * </pre>
49 * @since 1.5
50 * @see FutureTask
51 * @see Executor
52 *
53 * @spec JSR-166
54 * @revised $Date: 2003/08/19 15:04:57 $
55 * @editor $Author: tim $
56 * @author Doug Lea
57 */
58 public interface Future<V> extends Cancellable {
59
60 /**
61 * Waits if necessary for computation to complete, and then
62 * retrieves its result.
63 *
64 * @return computed result
65 * @throws CancellationException here???
66 * @throws ExecutionException if underlying computation threw an
67 * exception
68 * @throws InterruptedException if current thread was interrupted
69 * while waiting
70 */
71 V get() throws InterruptedException, ExecutionException;
72
73 /**
74 * Waits if necessary for at most the given time for the computation
75 * to complete, and then retrieves its result.
76 *
77 * @param timeout the maximum time to wait
78 * @param granularity the time unit of the timeout argument
79 * @return computed result
80 * @throws ExecutionException if underlying computation threw an
81 * exception
82 * @throws InterruptedException if current thread was interrupted
83 * while waiting
84 * @throws TimeoutException if the wait timed out
85 */
86 V get(long timeout, TimeUnit granularity)
87 throws InterruptedException, ExecutionException, TimeoutException;
88 }
89
90
91