{"id":473,"date":"2016-12-20T17:13:28","date_gmt":"2016-12-20T14:13:28","guid":{"rendered":"http:\/\/leodev.ru\/blog\/?p=473"},"modified":"2016-12-20T17:13:28","modified_gmt":"2016-12-20T14:13:28","slug":"%d0%bc%d0%b5%d1%82%d0%be%d0%b4%d1%8b-java-util-concurrent-completablefuture","status":"publish","type":"post","link":"https:\/\/leodev.ru\/blog\/java\/%d0%bc%d0%b5%d1%82%d0%be%d0%b4%d1%8b-java-util-concurrent-completablefuture\/","title":{"rendered":"\u041c\u0435\u0442\u043e\u0434\u044b java.util.concurrent.CompletableFuture"},"content":{"rendered":"<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Java8 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f\u00a0\u043a\u043b\u0430\u0441\u0441 <a href=\"http:\/\/download.java.net\/lambda\/b88\/docs\/api\/java\/util\/concurrent\/CompletableFuture.html\">CompletableFuture<\/a> \u2014 \u044d\u0442\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0413\u043e\u0432\u043e\u0440\u044f \u043f\u0440\u043e\u0449\u0435 \u044d\u0442\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, <em>\u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/em>, <em>\u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e<\/em> \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c\u0441\u044f. \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c, \u0447\u0442\u043e\u0431\u044b \u0432 \u043d\u0438\u0445 \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u043c\u0438\u043d\u043a\u0438 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 java.util.Function, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445.<!--more--><\/p>\n<pre class=\"lang:java decode:true\">\/\/ \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\r\nBiFunction&lt;T, U,R&gt; {\r\n  R apply(T t, U u);\r\n}\r\n\/\/ \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\r\nBiConsumer&lt;T,U&gt;  {\r\n  void  accept(T t, U u)\r\n}\r\n\/\/ \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\r\nFunction&lt;T, R&gt; {\r\n  R apply(T t);\r\n}\r\n\/\/ \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\r\nConsumer&lt;T&gt; {\r\n  void accept(T t);\r\n}\r\n\/\/ \u0411\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\r\nSupplier&lt;T&gt; {\r\n  T get();\r\n}\r\n<span class=\"hljs-comment\">\/\/ \u0411\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/span> \r\nRunnable { \r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">  void<\/span> <span class=\"hljs-title\">run<\/span><span class=\"hljs-params\">()<\/span><\/span>; \r\n}<\/pre>\n<p>\u042d\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u0442\u043e \u0435\u0441\u0442\u044c, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u044b \u043a\u0430\u043a \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0442\u0430\u043a \u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u043b\u0438 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<p>\u041a\u0430\u043a \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043b\u0430\u0441\u0441 <code>CompletableFuture<\/code> \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u0441\u0443\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u2014 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 (\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435) \u0438 \u043e\u043f\u043e\u0441\u0440\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0435 (\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435). \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f (<code>java.util.concurrent.Future<\/code>, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d java 5), \u043d\u043e \u0432 \u0446\u0435\u043b\u044f\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435. \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u0441\u0443\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c, \u044f \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0443 \u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044f\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u201c\u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 CompletableFuture\u201d \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u201c\u0444\u044c\u044e\u0447\u0435\u0440\u0441\u201d. \u00ab\u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0444\u044c\u044e\u0447\u0435\u0440\u0441, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<h4>1. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438<\/h4>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0434\u0432\u0430 \u2014 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">boolean<\/span> <span class=\"hljs-title\">complete<\/span><span class=\"hljs-params\">(T value)<\/span>\r\n<span class=\"hljs-keyword\">boolean<\/span> <span class=\"hljs-title\">completeExceptionally<\/span><span class=\"hljs-params\">(Throwable ex)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0441 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439.<\/p>\n<p>\u041f\u0440\u043e\u0447\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">boolean<\/span> <span class=\"hljs-title\">cancel<\/span><span class=\"hljs-params\">(<span class=\"hljs-keyword\">boolean<\/span> mayInterruptIfRunning)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d <code>completeExceptionally(new CancellationException)<\/code>. \u0412\u0432\u0435\u0434\u0435\u043d \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 java.util.concurrent.Future.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-keyword\">static<\/span> &lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;U&gt; <span class=\"hljs-title\">completedFuture<\/span><span class=\"hljs-params\">(U value)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d <code>CompletableFuture res=new CompletableFuture(); res.complete(value)<\/code>.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">obtrudeValue<\/span><span class=\"hljs-params\">(T value)<\/span>\r\n<span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">obtrudeException<\/span><span class=\"hljs-params\">(Throwable ex)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u041d\u0430\u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u0435\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412\u0435\u0440\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u0441\u0442\u0440\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u0432 \u043d\u043e\u0433\u0443.<\/p>\n<h4>2. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f<\/h4>\n<p>&nbsp;<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">boolean<\/span> <span class=\"hljs-title\">isDone<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0431\u044b\u043b \u043b\u0438 \u0443\u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">T <span class=\"hljs-title\">get<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0416\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0431\u0440\u043e\u0441\u0430\u0435\u0442 ExecutionException.<\/p>\n<p>\u041f\u0440\u043e\u0447\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">boolean<\/span> <span class=\"hljs-title\">isCancelled<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0431\u044b\u043b\u043e \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 cancel().<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">T <span class=\"hljs-title\">join<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0422\u043e \u0436\u0435, \u0447\u0442\u043e get(), \u043d\u043e \u0431\u0440\u043e\u0441\u0430\u0435\u0442 CompletionException.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">T <span class=\"hljs-title\">get<\/span><span class=\"hljs-params\">(<span class=\"hljs-keyword\">long<\/span> timeout, TimeUnit unit)<\/span>\r\n<\/span><\/code><\/pre>\n<p><code>get()<\/code> \u0441 \u0442\u0430\u0439\u043c-\u0430\u0443\u0442\u043e\u043c.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">T <span class=\"hljs-title\">getNow<\/span><span class=\"hljs-params\">(T valueIfAbsent)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e. \u0415\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>valueIfAbsent<\/code>.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">int<\/span> <span class=\"hljs-title\">getNumberOfDependents<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0434\u0440\u0443\u0433\u0438\u0445 CompletableFuture, \u0436\u0434\u0443\u0449\u0438\u0445 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e.<\/p>\n<h4>3. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u043f\u043e\u0441\u0440\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438<\/h4>\n<p>&nbsp;<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-keyword\">static<\/span> &lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;U&gt; <span class=\"hljs-title\">supplyAsync<\/span><span class=\"hljs-params\">(Supplier&lt;U&gt; supplier)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 supplier, \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441. \u0417\u0430\u043f\u0443\u0441\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u043f\u0443\u043b\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-keyword\">static<\/span> &lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;U&gt; <span class=\"hljs-title\">supplyAsync<\/span><span class=\"hljs-params\">(Supplier&lt;U&gt; supplier, Executor executor)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u043d\u0430 \u043f\u0443\u043b\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c executor.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">runAsync<\/span><span class=\"hljs-params\">(Runnable runnable)<\/span>\r\n<span class=\"hljs-keyword\">static<\/span> CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">runAsync<\/span><span class=\"hljs-params\">(Runnable runnable, Executor executor)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 <code>supplyAsync<\/code>, \u043d\u043e \u0430\u043a\u0446\u0438\u044f \u0442\u0438\u043f\u0430 <code>Runnable<\/code> \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0442\u0438\u043f\u0430 <code>Void<\/code>.<\/p>\n<h4>4. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u043f\u043e\u0441\u0440\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f<\/h4>\n<p>\u041f\u0440\u0435\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (\u0440\u0435\u0430\u043a\u0446\u0438\u044e) \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u044d\u0442\u043e\u0433\u043e (\u0438\/\u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e) \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430. \u0421\u0430\u043c\u044b\u0439 \u043e\u0431\u0448\u0438\u0440\u043d\u044b\u0439 \u0441\u0443\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u043f\u043e \u0434\u0432\u0443\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c:<\/p>\n<p>\u0430) \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0440\u0435\u0430\u043a\u0446\u0438\u0438 \u043d\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435: \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430, \u0438\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043f\u0443\u043b\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u043e\u043c Async (\u0432 \u0434\u0432\u0443\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445 \u2014 \u0437\u0430\u043f\u0443\u0441\u043a \u043d\u0430 \u043e\u0431\u0449\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0435 <code>ForkJoinPool.commonPool()<\/code>, \u043b\u0438\u0431\u043e \u043d\u0430 \u043f\u043e\u0442\u043e\u043a\u0435, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c). \u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430.<\/p>\n<p>\u0431) \u0442\u043e\u043f\u043e\u043b\u043e\u0433\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0434\u0430\u043d\u043d\u044b\u043c \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u043c \u0438 \u0440\u0435\u0430\u043a\u0446\u0438\u0435\u0439 \u043d\u0430 \u0435\u0433\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435: \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f, \u0442\u0438\u043f\u0430 \u201cany\u201c \u0438 \u0442\u0438\u043f\u0430 \u201dall\u201d.<\/p>\n<p>\u2014 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c: \u043e\u0434\u0438\u043d \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0440\u0435\u0430\u043a\u0446\u0438\u044e<\/p>\n<p>\u2014 \u0441\u043f\u043e\u0441\u043e\u0431 \u201cany\u201d \u2014 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0434\u0432\u0430 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430; \u043f\u0435\u0440\u0432\u044b\u0439 (\u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438) \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u0430\u043a\u0446\u0438\u044e; \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f<\/p>\n<p>\u2014 \u0441\u043f\u043e\u0441\u043e\u0431 \u201call\u201d \u2014 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0434\u0432\u0430 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u0441\u0435\u0445 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0430\u043a\u0446\u0438\u044e.<\/p>\n<h5>4.1 \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430 (\u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c)<\/h5>\n<p>\u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u043c\u0435\u044e\u0442 \u0438\u043c\u0435\u043d\u0430, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 then, \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u0440\u0435\u0430\u043a\u0446\u0438\u044e, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0442\u0438\u043f\u0430 <code>CompletableFuture <\/code>\u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043a\u0446\u0438\u0438. \u0420\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0442\u0438\u043f\u0443 \u0440\u0435\u0430\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"java hljs\">&lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;U&gt; <span class=\"hljs-title\">thenApply<\/span><span class=\"hljs-params\">(Function&lt;? <span class=\"hljs-keyword\">super<\/span> T,? extends U&gt; fn)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">thenAccept<\/span><span class=\"hljs-params\">(Consumer&lt;? <span class=\"hljs-keyword\">super<\/span> T&gt; block)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0420\u0435\u0430\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430, \u043d\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e<br \/>\n\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430 \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f <code>Void<\/code>.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">thenRun<\/span><span class=\"hljs-params\">(Runnable action)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0420\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0438 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0443\u0441\u0442\u044c compute1..compute4 \u2014 \u044d\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u044b. \u041b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442 \u0448\u0430\u0433\u0430 \u043a \u0448\u0430\u0433\u0443 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java hljs\">supplyAsync(compute1)\r\n  .thenApply(compute2)\r\n  .thenApply(compute3)\r\n  .thenAccept(compute4);\r\n<\/code><\/pre>\n<p>\u0447\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0432\u044b\u0437\u043e\u0432\u0443<\/p>\n<pre><code class=\"java hljs\">compute4(compute3(compute2(compute1())));\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre><code class=\"java hljs\">&lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;U&gt; <span class=\"hljs-title\">thenCompose<\/span><span class=\"hljs-params\">(Function&lt;? <span class=\"hljs-keyword\">super<\/span> T, CompletableFuture&lt;U&gt;&gt; fn)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0422\u043e \u0436\u0435, \u0447\u0442\u043e <code>thenApply<\/code>, \u043d\u043e \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u0441\u0430\u043c\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0432\u043c\u0435\u0441\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0442\u043e\u043f\u043e\u043b\u043e\u0433\u0438\u0438.<\/p>\n<h5>4.2 \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u043c\u043d\u043e\u0433\u0438\u0445 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432<\/h5>\n<p>&nbsp;<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> CompletableFuture&lt;Object&gt; <span class=\"hljs-title\">anyOf<\/span><span class=\"hljs-params\">(CompletableFuture&lt;?&gt;... cfs)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>cfs<\/code>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430.<\/p>\n<h5>4.3 \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432<\/h5>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"java hljs\">&lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;U&gt; <span class=\"hljs-title\">applyToEither<\/span><span class=\"hljs-params\">(CompletableFuture&lt;? extends T&gt; other, Function&lt;? <span class=\"hljs-keyword\">super<\/span> T,U&gt; fn)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u043b\u0438\u0431\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>other<\/code>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e:<\/p>\n<pre><code class=\"java hljs\">CompletableFuture.anyOf(<span class=\"hljs-keyword\">this<\/span>, other).thenApply(fn);\r\n<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0442\u0438\u043f\u043e\u043c \u0440\u0435\u0430\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">acceptEither<\/span><span class=\"hljs-params\">(CompletableFuture&lt;? extends T&gt; other, Consumer&lt;? <span class=\"hljs-keyword\">super<\/span> T&gt; block)<\/span>\r\nCompletableFuture&lt;Void&gt; <span class=\"hljs-title\">runAfterEither<\/span><span class=\"hljs-params\">(CompletableFuture&lt;?&gt; other, Runnable action)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u041d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0437\u0430\u0447\u0435\u043c \u0431\u044b\u043b\u043e \u0434\u0435\u043b\u0430\u0442\u044c 3 \u043c\u0435\u0442\u043e\u0434\u0430 *Either (9 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c *Async \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432), \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0434\u043d\u043e\u0433\u043e:<\/p>\n<pre><code class=\"java hljs\">&lt;T&gt; <span class=\"hljs-function\">CompletableFuture&lt;T&gt; <span class=\"hljs-title\">either<\/span><span class=\"hljs-params\">(CompletableFuture&lt;? extends T&gt; other)<\/span> <\/span>{\r\n  <span class=\"hljs-keyword\">return<\/span> CompletableFuture.anyOf(<span class=\"hljs-keyword\">this<\/span>, other);\r\n}<\/code><\/pre>\n<p>\u0442\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u043a\u0430\u043a:<\/p>\n<pre><code class=\"java hljs\">f1.applyToEither(other, fn) == f1.either(other).thenApply(fn);\r\nf1.applyToEitherAsync(other, fn) == f1.either(other).thenApplyAsync(fn);\r\nf1.applyToEitherAsync(other, fn, executor) == f1.either(other).thenApplyAsync(fn, executor);\r\nf1.acceptEither(other, block) == f1.either(other).thenAccept(other);\r\nf1.runAfterEither(other, action) == f1.either(other).thenRun(action);\r\n<\/code><\/pre>\n<p>\u0438 \u0442.\u043f. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u0435\u0442\u043e\u0434 either \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f\u0445.<\/p>\n<h5>4.4 \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u0434\u0432\u0443\u0445 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432<\/h5>\n<p>&nbsp;<\/p>\n<pre><code class=\"java hljs\">&lt;U,V&gt; <span class=\"hljs-function\">CompletableFuture&lt;V&gt;     <span class=\"hljs-title\">thenCombine<\/span><span class=\"hljs-params\">(CompletionStage&lt;? extends U&gt; other, BiFunction&lt;? <span class=\"hljs-keyword\">super<\/span> T,? <span class=\"hljs-keyword\">super<\/span> U,? extends V&gt; fn)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434. \u0418\u043c\u0435\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0434\u0432\u0430 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0430\u043a\u0446\u0438\u044e, \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0439\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u043e\u0442 \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0447\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u0438\u043f\u043e\u043c \u0440\u0435\u0430\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java hljs\">&lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">thenAcceptBoth<\/span><span class=\"hljs-params\">(CompletableFuture&lt;? extends U&gt; other, BiConsumer&lt;? <span class=\"hljs-keyword\">super<\/span> T,? <span class=\"hljs-keyword\">super<\/span> U&gt; block)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">runAfterBoth<\/span><span class=\"hljs-params\">(CompletableFuture&lt;?&gt; other, Runnable action)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<h5>4.5 \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043c\u043d\u043e\u0433\u0438\u0445 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432<\/h5>\n<p>&nbsp;<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> CompletableFuture&lt;Void&gt; <span class=\"hljs-title\">allOf<\/span><span class=\"hljs-params\">(CompletableFuture&lt;?&gt;... cfs)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 CompletableFuture, \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0432\u0441\u0435\u0445 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u2014 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0432\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430\u0445-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445, \u0442\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b, \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<h5>4.6. \u041f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h5>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u044d\u0442\u0430\u043f\u0435 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e, \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u0441\u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443 \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"java hljs\"><span class=\"hljs-function\">CompletableFuture&lt;T&gt; <span class=\"hljs-title\">exceptionally<\/span><span class=\"hljs-params\">(Function&lt;Throwable,? extends T&gt; fn)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c, \u0432\u044b\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>fn<\/code>. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441 \u0442\u0435\u043c \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c.<\/p>\n<pre><code class=\"java hljs\">&lt;U&gt; <span class=\"hljs-function\">CompletableFuture&lt;U&gt; <span class=\"hljs-title\">handle<\/span><span class=\"hljs-params\">(BiFunction&lt;? <span class=\"hljs-keyword\">super<\/span> T,Throwable,? extends U&gt; fn)<\/span>\r\n<\/span><\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0437\u0430\u0432\u0430\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0438\u043b\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e. \u0415\u0441\u043b\u0438 \u0444\u044c\u044e\u0447\u0435\u0440\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c <code>r<\/code>, \u0442\u043e \u0432 \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<code> (r, null)<\/code>, \u0435\u0441\u043b\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c ex, \u0442\u043e \u0432 \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<code> (null, ex)<\/code>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0435\u0430\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u0435\u0436\u0435\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u044c\u044e\u0447\u0435\u0440\u0441\u0430.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0437\u044f\u0442 \u0438\u0437 <a href=\"http:\/\/nurkiewicz.blogspot.ru\/2013\/05\/java-8-definitive-guide-to.html\">http:\/\/nurkiewicz.blogspot.ru\/2013\/05\/java-8-definitive-guide-to.html<\/a>:<\/p>\n<pre><code class=\"java hljs\">CompletableFuture&lt;Integer&gt; safe = future.handle((r, ex) -&gt; {\r\n    <span class=\"hljs-keyword\">if<\/span> (r != <span class=\"hljs-keyword\">null<\/span>) {\r\n            <span class=\"hljs-keyword\">return<\/span> Integer.parseInt(r);\r\n    } <span class=\"hljs-keyword\">else<\/span> {\r\n            log.warn(<span class=\"hljs-string\">\"Problem\"<\/span>, ex);\r\n            <span class=\"hljs-keyword\">return<\/span> -<span class=\"hljs-number\">1<\/span>;\r\n    }\r\n});\r\n<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>future <\/code>\u0432\u044b\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u0438\u043f\u0430 <code>String <\/code>\u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043a\u0443, \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u044b\u0434\u0430\u0435\u0442 -1. \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430\u0434\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0441 <code>if (ex!=null)<\/code>, \u0442\u0430\u043a \u043a\u0430\u043a <code>r==null<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u043c, \u0442\u0430\u043a \u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438, \u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043b\u0443\u0447\u0430\u0439 <code>r==null<\/code> \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u0417\u0430\u043c\u0435\u0442\u043a\u0430 \u0432\u0437\u044f\u0442\u0430 \u0443 <a class=\"author-info__name\" href=\"https:\/\/habrahabr.ru\/users\/rfq\">\u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u041a\u0430\u0439\u0433\u043e\u0440\u043e\u0434\u043e\u0432<\/a> <a class=\"author-info__nickname\" href=\"https:\/\/habrahabr.ru\/users\/rfq\">@rfq<\/a>:\u00a0https:\/\/habrahabr.ru\/post\/213319\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Java8 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f\u00a0\u043a\u043b\u0430\u0441\u0441 CompletableFuture \u2014 \u044d\u0442\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0413\u043e\u0432\u043e\u0440\u044f \u043f\u0440\u043e\u0449\u0435 \u044d\u0442\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c\u0441\u044f. \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 &hellip; <a href=\"https:\/\/leodev.ru\/blog\/java\/%d0%bc%d0%b5%d1%82%d0%be%d0%b4%d1%8b-java-util-concurrent-completablefuture\/\" class=\"more-link\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435<span class=\"screen-reader-text\"> \u00ab\u041c\u0435\u0442\u043e\u0434\u044b java.util.concurrent.CompletableFuture\u00bb<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[74,169,168],"class_list":["post-473","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","tag-java-8","tag-168"],"_links":{"self":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":3,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"predecessor-version":[{"id":476,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/473\/revisions\/476"}],"wp:attachment":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}