That java.util.concurrent.Future<V>. The related Javadoc is pretty clear and contains an example. For the lazy, here's copypaste:
A Future . , , . get , , . . , . , . Future , , Future<?> return null .
( , .)
interface ArchiveSearcher { String search(String target); }
class App {
ExecutorService executor = ...
ArchiveSearcher searcher = ...
void showSearch(final String target)
throws InterruptedException {
Future<String> future
= executor.submit(new Callable<String>() {
public String call() {
return searcher.search(target);
}});
displayOtherThings();
try {
displayText(future.get());
} catch (ExecutionException ex) { cleanup(); return; }
}
}
FutureTask - Future, Runnable, Executor. , submit :
FutureTask<String> future =
new FutureTask<String>(new Callable<String>() {
public String call() {
return searcher.search(target);
}});
executor.execute(future);
: , Future.get() .
FutureWrapper Future.