/* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain. Use, modify, and * redistribute this code in any way without acknowledgement. */ package java.util.concurrent; /** * A Future represents the result of an asynchronous * computation. Methods are provided to check if the computation is * complete, to wait for its completion, and to retrieve the result of * the computation. The result can only be retrieved using method * get when the computation has completed, blocking if * necessary until it is ready. Once the computation has completed, * the computation cannot be cancelled. * *
* Sample Usage (Note that the following classes are all * made-up.)
*
* interface ArchiveSearcher { String search(String target); } * class App { * Executor executor = ... * ArchiveSearcher searcher = ... * void showSearch(final String target) throws InterruptedException { * Future<String> future = * new FutureTask<String>(new Callable<String>() { * public String call() { * return searcher.search(target); * }}); * executor.execute(future); * displayOtherThings(); // do other things while searching * try { * displayText(future.get()); // use future * } catch (ExecutionException ex) { cleanup(); return; } * } * } ** * The {@link Executors} class contains more convenient methods * for common usages. For example, the above explicit * construction could be replaced with: *
* Future<String> future = Executors.execute(executor, * new Callable<String>() { * public String call() { * return searcher.search(target); * }}); ** @see FutureTask * @see Executor * @since 1.5 * @author Doug Lea */ public interface Future