What would you use "Future" for the App Engine?

In docs , FutureWrapper is defined as follows:

FutureWrapper is a simple future that completes the parent future.

What is the future, why do you need to wrap it and when will you use it in the App Engine?

+3
source share
1 answer

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(); // do other things while searching
     try {
       displayText(future.get()); // use future
     } 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.

+1

Source: https://habr.com/ru/post/1734982/


All Articles