| Callable.java |
1 /*
2 * %W% %E%
3 *
4 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
5 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6 */
7
8 package java.util.concurrent;
9
10 /**
11 * A task that returns a result and may throw an exception.
12 * Implementors define a single method with no arguments called
13 * <tt>call</tt>.
14 *
15 * <p>The <tt>Callable</tt> interface is similar to {@link
16 * java.lang.Runnable}, in that both are designed for classes whose
17 * instances are potentially executed by another thread. A
18 * <tt>Runnable</tt>, however, does not return a result and cannot
19 * throw a checked exception.
20 *
21 * <p> The {@link Executors} class contains utility methods to
22 * convert from other common forms to <tt>Callable</tt> classes.
23 *
24 * @see Executor
25 * @since 1.5
26 * @author Doug Lea
27 * @param <V> the result type of method <tt>call</tt>
28 */
29 public interface Callable<V> {
30 /**
31 * Computes a result, or throws an exception if unable to do so.
32 *
33 * @return computed result
34 * @throws Exception if unable to compute a result
35 */
36 V call() throws Exception;
37 }
38