{"id":287936,"date":"2018-08-16T14:19:34","date_gmt":"2018-08-16T10:19:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=287936"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=287936","title":{"rendered":"\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445: \u0440\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 java.util.concurrent.CompletableFuture"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/418547\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0440\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f, \u0435\u0441\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043a\u0440\u044b\u0442?<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0442\u0430\u043c \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0441\u043e\u043a\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439, \u0442\u0440\u0443\u0434\u043d\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u0432 \u043f\u0435\u0434\u0430\u0433\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043b\u0430\u043d\u0435. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u043e \u0438\u0445 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u043c, \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u0439, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u0445\u043e\u0442\u044f, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u044d\u043a\u043e\u043d\u043e\u043c\u043d\u044b\u0439 \u043f\u043e \u0440\u0430\u0441\u0445\u043e\u0434\u0443 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public static &lt;U&gt; CompletableFuture&lt;U&gt; supplyAsync(Supplier&lt;U&gt; supplier,                                                    Executor executor) Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier. Type Parameters: U - the function's return type Parameters: supplier - a function returning the value to be used to complete the returned CompletableFuture executor - the executor to use for asynchronous execution Returns: the new CompletableFuture<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">Returns a new CompletableFuture<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>CompletableFuture<\/code> \u043b\u0438\u0431\u043e \u0435\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">that is asynchronously completed by a task running in the given executor`<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u0430\u044f \u043d\u0430 <code>Executor<\/code>&#8216;e.<br \/>  \u041a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0435\u043c, <code>Executor<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0442\u0438\u043f\u0430 <code>Runnable<\/code>.<br \/>  Runnable \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u2014 \u0442\u0430\u043a \u043c\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\"> completed ... with the value obtained by calling the given Supplier.<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 <code>Runnable<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 <code>Supplier<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 <code>CompletableFuture<\/code>.<\/p>\n<p>  <\/p>\n<p><code>Supplier<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    class CompletableFutureForSupplyAsync&lt;U&gt; extends CompletableFuture&lt;U&gt; implements Runnable {         Supplier&lt;U&gt; supplier;          public CompletableFutureForSupplyAsync(Supplier&lt;U&gt; supplier) {             this.supplier = supplier;         }          public void run() {             try {                 U result = supplier.get();                 super.complete(result);             } catch (Throwable e) {                 super.completeExceptionally(e);             }         }     }      public static &lt;U&gt; CompletableFuture&lt;U&gt; supplyAsync(Supplier&lt;U&gt; supplier,                                                        Executor executor) {         CompletableFutureForSupplyAsync&lt;U&gt; task = new CompletableFutureForSupplyAsync&lt;&gt;(supplier);         executor.execute(task);         return task;     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public &lt;U&gt; CompletableFuture&lt;U&gt; thenApplyAsync(Function&lt;? super T,? extends U&gt; fn,                                                Executor executor) Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor,   with this stage's result as the argument to the supplied function.    See the CompletionStage documentation for rules covering exceptional completion. Specified by: thenApplyAsync in interface CompletionStage&lt;T&gt; Type Parameters: U - the function's return type Parameters: fn - the function to use to compute the value of the returned CompletionStage executor - the executor to use for asynchronous execution Returns: the new CompletionStage <\/code><\/pre>\n<p>  <\/p>\n<p><code>Returns a new CompletionStage that... is executed using the supplied Executor<\/code><\/p>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043f\u0440\u044f\u043c\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 <code>Runnable<\/code>.<\/p>\n<p>  <\/p>\n<p><code>... with this stage's result as the argument to the supplied function.<\/code> <\/p>\n<p>  <\/p>\n<p>\u0430 \u0432\u043e\u0442 \u044d\u0442\u043e \u0443\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u0430\u044f \u043d\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0441\u043b\u0443\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 <code>CompletionStage<\/code>. \u0412 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 <code>thenApplyAsync<\/code> \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 <code>Executor<\/code> \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c <code>CompletionStage<\/code>,<br \/>  \u0447\u0442\u043e\u0431\u044b \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0430 \u0441\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0437\u0430\u0434\u0430\u0447\u0443. \u0421\u0440\u0435\u0434\u0438 \u043c\u043d\u043e\u0433\u043e\u0447\u0435\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <code>CompletionStage<\/code> \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d, \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0449\u0438\u0439 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438, \u044d\u0442\u043e <code>whenComplete<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public CompletableFuture&lt;T&gt; whenComplete(BiConsumer&lt;? super T,? super Throwable&gt; action) Returns a new CompletionStage with the same result or exception as this stage, that executes the given action when this stage completes.<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0432\u043e \u0432\u043d\u043e\u0432\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435-\u0437\u0430\u0434\u0430\u0447\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0449\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>BiConsumer<\/code> \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">     class CompletableFutureForApplyAsync&lt;T, U&gt; extends CompletableFuture&lt;U&gt;             implements Runnable, BiConsumer&lt;T,Throwable&gt;     {         Function&lt;? super T,? extends U&gt; fn;         Executor executor;         T arg;         Throwable throwable;          public CompletableFutureForApplyAsync(Function&lt;? super T,? extends U&gt; fn, Executor executor) {             this.fn = fn;             this.executor = executor;         }          @Override   \/\/ implementation of BiConsumer interface         public void accept(T argument, Throwable throwable) {             if (throwable != null) {                 this.throwable = throwable;             } else {                 this.arg = argument;             }             executor.execute(this);         }          @Override         public void run() {             if (throwable == null) {                 try {                     U result = fn.apply(arg);                     super.complete(result);                 } catch (Throwable e) {                     super.completeExceptionally(e);                 }             } else {                 super.completeExceptionally(throwable);             }         }     }      public &lt;U&gt; CompletableFuture&lt;U&gt; thenApplyAsync(Function&lt;? super T,? extends U&gt; fn,                                                    Executor executor     ) {         CompletableFutureForApplyAsync&lt;T,U&gt; task = new CompletableFutureForApplyAsync&lt;&gt;(fn, executor);         this.whenComplete(task);         return task;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0440\u043e\u0434\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043c \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<p>  <\/p>\n<p>1) \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">     CompletableFutureForApplyAsync&lt;T,U&gt; task = new CompletableFutureForApplyAsync&lt;&gt;(fn, executor);<\/code><\/pre>\n<p>  <\/p>\n<p>2) \u043e\u043d\u0430 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0433\u043e\u0442\u043e\u0432\u0430 \u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0440\u043e\u0441\u0438\u043c \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0430\u043c \u044d\u0442\u043e\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u0432\u044b\u0437\u0432\u0430\u0432 \u043f\u043e\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">       this.whenComplete(task);<\/code><\/pre>\n<p>  <\/p>\n<p>3) \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u043c\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u043d\u043e \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 (\u0441\u043c \u043c\u0435\u0442\u043e\u0434 <code>accept<\/code>()).<\/p>\n<p>  <\/p>\n<p>4) \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u0434\u0430\u043d\u043e\u0439 \u043d\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<br \/>  \u042d\u0442\u043e\u0442 \u0440\u0435\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>whenComplete<\/code>(), \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u0436\u0435 \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u043e\u0432\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. \u041d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u044d\u0442\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430. <\/p>\n<p>  <\/p>\n<p>A \u043a\u0430\u043a \u0436\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0442\u0432\u0438?<br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 <code>thenCombineAsync<\/code>. <\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0441 \u043e\u0434\u043d\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u2014 \u0441 \u0434\u0432\u0443\u043c\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u043e\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">ublic &lt;U,V&gt; CompletableFuture&lt;V&gt; thenCombineAsync(CompletionStage&lt;? extends U&gt; other,                                                    BiFunction&lt;? super T,? super U,? extends V&gt; fn,                                                    Executor executor) Description copied from interface: CompletionStage Returns a new CompletionStage that, when this and the other given stage complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function. <\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 <code>thenApplyAsync<\/code>, \u043d\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u0436\u0435 \u043e\u0442 \u0434\u0432\u0443\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>CompletionStage&lt;? extends U&gt; other<\/code>, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u043e\u043c \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0436\u0435 \u043d\u0430\u043c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430? <\/p>\n<p>  <\/p>\n<p>\u041d\u0443 \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>T arg<\/code> \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0432\u0435: <code>T arg1; U arg2;<\/code>, a \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 public <code>void accept(T argument, Throwable throwable)<\/code> \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0432\u0430 \u2014 <code>accept1<\/code> \u0438 <code>accept2<\/code>,<br \/>  \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0430\u0448 \u0441\u0442\u0440\u043e\u044f\u0449\u0438\u0439\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u043d\u0435 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>BiConsumer&lt;T,Throwable&gt;<\/code> \u0438 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0443\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0443\u0437\u043b\u043e\u0432 \u0433\u0440\u0430\u0444\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        this.whenComplete(task);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043e\u0431\u044a\u0435\u043a\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434, \u0431\u0435\u0437 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        this.whenComplete(task::accept1);         other.whenComplete(task::accept2);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>this<\/code> \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u0430 \u043e\u0431\u044a\u0435\u043a\u0442 <code>other<\/code> \u2014 \u0432\u0442\u043e\u0440\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435 \u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        public synchronized void accept1(T argument, Throwable throwable) {             if (throwable != null) {                 this.throwable = throwable;                 executor.execute(this);             } else {                 this.arg1 = argument;                 if (arg2 != null) {                     executor.execute(this);                 }             }         }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 accept2.<\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0442\u0430\u043b\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 (\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043e\u0431\u0449\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438)<\/li>\n<li>\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0436\u0434\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e.<\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\u043c \u043d\u0430 <strong><code>null<\/code><\/strong> \u2014 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043c\u043e\u0436\u0435\u0442, \u043d\u0430\u0434\u043e \u0437\u0430\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0431\u0443\u043b\u0435\u0432\u0441\u043a\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0438 \u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0447\u0435\u043c \u0434\u0432\u0430, \u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043c\u044b\u0441\u043b\u044c \u2014 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0435 \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0441\u0432\u043e\u0439 \u043c\u0435\u0442\u043e\u0434, \u0430 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432?<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    Parameter&lt;Integer&gt; arg1 = new Parameter&lt;&gt;();     Parameter&lt;Float&gt; arg2 = new Parameter&lt;&gt;();     ...      future1.whenComplete(arg1);     future2.whenComplete(arg2);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430, \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437.<\/p>\n<p>  <\/p>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u0440\u0435\u0437\u044e\u043c\u0435 \u0438\u0437 \u0432\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u2014 \u044d\u0442\u043e \u0441\u0435\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440,<br \/>  \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043e\u0442\u043e\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u2014 \u0441\u0435\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (threads).<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0441\u0432\u044f\u0437\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0442\u043e\u043a\u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u0432, \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432,<br \/>  \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442 \u043f\u043e\u0442\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f, \u0435\u0441\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0435\u0449\u0435 \u043d\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b\u0430, \u043d\u043e \u043f\u043e\u0442\u043e\u043a \u0443\u0436\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0435\u0435 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pull-based \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0437\u0430\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043f\u043e\u043a\u0430 \u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0430 \u0432\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f.<br \/>  \u041e\u043d\u0438 \u043f\u0430\u0441\u0441\u0438\u0432\u043d\u043e \u0436\u0434\u0443\u0442, \u043f\u043e\u043a\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441\u0430\u043c\u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0443\u0442 \u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e push-based \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<br \/>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u043d\u0435 \u0442\u0440\u0430\u0442\u044f\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0430 \u0441\u0442\u0435\u043a \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0441\u0435\u0442\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044e \u0438\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0442\u043e\u0447\u043d\u0435\u0435, \u043a \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044e \u0438\u0445 \u043f\u043e\u0434\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432: \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0430\u0434\u0440\u0435\u0441 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <code>CompletableFuture<\/code> \u0440\u043e\u0432\u043d\u043e \u044d\u0442\u043e \u0438 \u0434\u0435\u043b\u0430\u0435\u0442, \u0438 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0431\u0435\u0437 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u044f\u0432\u043d\u043e, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<br \/>  \u041d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0438\u043c\u0435\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0442\u0435\u043c, \u0447\u0442\u043e \u0431\u044b\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u044d\u0442\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<br \/>  \u041f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 <code>java.util.concurrent<\/code> \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u043b\u0438 \u043d\u0435 \u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u0442\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0438 \u0441\u043a\u0440\u044b\u043b\u0438 \u0438\u0445 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0435 \u043a\u043e\u0434\u0430 <code>CompletableFuture<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435, \u043a\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u0433\u043b\u0430\u0437\u0430\u043c\u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u043c\u043e\u0433\u0443\u0442 \u0440\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u044b, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 <a href=\"https:\/\/github.com\/akaigoro\/CodeSamples\/blob\/master\/src\/habr\/completablefuture_model\/CompletableFutureModel.java\">\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 \u0413\u0438\u0442\u0445\u0430\u0431\u0435<\/a>.<\/p>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/418547\/\"> https:\/\/habr.com\/post\/418547\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/418547\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0440\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f, \u0435\u0441\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043a\u0440\u044b\u0442?<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0442\u0430\u043c \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0441\u043e\u043a\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439, \u0442\u0440\u0443\u0434\u043d\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u0432 \u043f\u0435\u0434\u0430\u0433\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043b\u0430\u043d\u0435. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u043e \u0438\u0445 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u043c, \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u0439, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u0445\u043e\u0442\u044f, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u044d\u043a\u043e\u043d\u043e\u043c\u043d\u044b\u0439 \u043f\u043e \u0440\u0430\u0441\u0445\u043e\u0434\u0443 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-287936","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=287936"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287936\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}