﻿{"id":1096,"date":"2013-07-08T00:14:57","date_gmt":"2013-07-07T15:14:57","guid":{"rendered":"http:\/\/yucchi.jp\/blog\/?p=1096"},"modified":"2013-07-08T00:36:12","modified_gmt":"2013-07-07T15:36:12","slug":"completablefuture-%e3%82%92%e8%a7%a3%e3%82%89%e3%81%aa%e3%81%84%e3%81%be%e3%81%be%e8%a9%a6%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"http:\/\/yucchi.jp\/blog\/?p=1096","title":{"rendered":"CompletableFuture \u3092\u89e3\u3089\u306a\u3044\u307e\u307e\u8a66\u3057\u3066\u307f\u305f"},"content":{"rendered":"<p>Java8 \u306e\u76ee\u7389\u6a5f\u80fd\u306f\u4e26\u884c\u51e6\u7406\u3092\u5bb9\u6613\u306b\u3059\u308b\u305f\u3081\u306b\u63a1\u7528\u3055\u308c\u305f Lambda \u306b\u6ce8\u76ee\u304c\u96c6\u307e\u3063\u3066\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u4ed6\u306b\u3082\u4fbf\u5229\u306a\u6a5f\u80fd\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u4f55\u6545\u304b<span style=\"color: #ff0000; font-size: medium;\"><strong>\u4eba\u6c17\u306e\u7121\u3044\uff1f CompletableFuture<\/strong><\/span> \u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u308c\u3082\u5916\u56fd\u8a9e\u306e\u30b5\u30a4\u30c8\u304b\u3089\u306e\u60c5\u5831\u3092\u5143\u306b\u89e3\u3089\u306a\u3044\u307e\u307e\u30b4\u30cb\u30e7\u30b4\u30cb\u30e7\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b CompletableFuture \u306e\u60c5\u5831\u306f\u30b0\u30fc\u30b0\u30eb\u5148\u751f\u306b\u805e\u3044\u3066\u307f\u3066\u3082\u65b0\u3057\u3044\u60c5\u5831\u306f\u6570\u4ef6\u3057\u304b\u30d2\u30c3\u30c8\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u8ab0\u304b\u304c\u65e5\u672c\u8a9e\u3067\u512a\u3057\u304f\u89e3\u8aac\u3057\u3066\u304f\u308c\u308b\u306e\u3092\u5f85\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c Lambda \u306e\u4eba\u6c17\u306e\u9ad8\u3055\u304b\u3089\u304b\u898b\u5411\u304d\u3082\u3055\u308c\u306a\u3044\u53ef\u611b\u305d\u3046\u306a\u5b50\u3068\u306a\u3063\u3066\u307e\u3059\u3002\uff08\u30f2\u30d2<\/p>\n<p>CompletableFuture \u3063\u3066\u3044\u3063\u305f\u3044\u4f55\u8005\u306a\u306e\uff1f<\/p>\n<p>\u3053\u308c\u307e\u3067\u306f\u975e\u540c\u671f\u51e6\u7406\u306e\u8fd4\u308a\u5024\u3092\u53d6\u308b\u305f\u3081\u306b\u306f ExecutorService\u3001 Callable\u3001Future \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e CompletableFuture \u3092\u4f7f\u3048\u3070\u305d\u308c\u3089\u3092\u7c21\u5358\u306b\u3067\u304d\u3061\u3083\u3046\u3088\u3063\u3066\u512a\u308c\u3082\u306e\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3060\u3044\u305f\u3044\u306e\u6d41\u308c\u3092\u30b5\u30af\u30c3\u3068\u8aac\u660e\u3059\u308b\u3068\u3001<\/p>\n<p>\u305d\u308c\u305e\u308c\u3001countHoge() , countFuga() , countChome() \u3068\u8a00\u3046\u30e1\u30bd\u30c3\u30c9\u3067\u6642\u9593\u306e\u304b\u304b\u308b\u8a08\u7b97\u7d50\u679c\u3092\u53d6\u5f97\u3059\u308b\u3082\u306e\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u305e\u308c 1 \u79d2\u30013 \u79d2\u30017 \u79d2\u3068\u8a08\u7b97\u6642\u9593\u3092\u8981\u3057\u307e\u3059\u3002<\/p>\n<p>\u8fd4\u308a\u5024\u306f\u30011 \u30013 \u30017 \u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093 ExecutorService \u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u305e\u308c CompletableFuture.supplyAsync() \u306b\u3066 CompletableFuture \u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>CompletableFuture.allOf() \u30e1\u30bd\u30c3\u30c9\u306b\u3066\u305d\u308c\u305e\u308c\u3092\u3072\u3068\u307e\u3068\u3081\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>thenRun() \u30e1\u30bd\u30c3\u30c9\u306b\u3066 \u51e6\u7406\u3092\u958b\u59cb\u3057\u3001\u8a08\u7b97\u7d50\u679c\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u306f get() \u30e1\u30bd\u30c3\u30c9\u306b\u3066\u8a08\u7b97\u7d50\u679c\u3092\u53d6\u5f97\u3059\u308c\u3070\u3044\u3044\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u8fd4\u308a\u5024\u3092\u5229\u7528\u3057\u3066\u65b0\u305f\u306b CompletableFuture&lt;T&gt; \u3092\u4f5c\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e CompletableFuture \u30af\u30e9\u30b9\u306b\u306f 50 \u7a2e\u985e\u307b\u3069\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u308b\u306e\u3067\u304b\u306a\u308a\u81ea\u7531\u5ea6\u304c\u9ad8\u304f\u3044\u308d\u3093\u306a\u3053\u3068\u304c\u3067\u304d\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u826f\u304f\u89e3\u3089\u306a\u3044\u306e\u306b\u9069\u5f53\u306b\u5275\u3063\u305f\u30b3\u30fc\u30c9\u306a\u306e\u3067\u9593\u9055\u3044\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u7b11\u3063\u3066\u8a31\u3057\u3066\u304f\u3060\u3055\u3044\u307e\u305b\u3002<\/p>\n<pre title=\"SomeWorks.java\">\r\npackage jp.yucchi.trycompletablefuture;\r\n\r\npublic class SomeWorks {\r\n    public int countHoge()\r\n\t{\r\n\t\ttry {Thread.sleep(1_000);}catch(InterruptedException e){throw new RuntimeException(e);}\r\n\t\treturn 1;\r\n\t}\r\n\r\n\tpublic int countFuga()\r\n\t{\r\n\t\ttry {Thread.sleep(3_000);}catch(InterruptedException e){throw new RuntimeException(e);}\r\n\t\treturn 3;\r\n\t}\r\n\r\n\tpublic int countChome()\r\n\t{\r\n\t\ttry {Thread.sleep(7_000);}catch(InterruptedException e){throw new RuntimeException(e);}\r\n\t\treturn 7;\r\n\t}\r\n\r\n}\r\n\r\n<\/pre>\n<pre title=\"TryCompletableFuture.java\">\r\npackage jp.yucchi.trycompletablefuture;\r\n\r\nimport java.lang.management.ManagementFactory;\r\nimport java.util.concurrent.CompletableFuture;\r\nimport java.util.concurrent.ExecutionException;\r\nimport java.util.concurrent.ExecutorService;\r\nimport java.util.concurrent.Executors;\r\nimport java.util.concurrent.TimeUnit;\r\nimport java.util.logging.Level;\r\nimport java.util.logging.Logger;\r\n\r\npublic class TryCompletableFuture {\r\n\r\n    private static final SomeWorks works = new SomeWorks();\r\n    private static ExecutorService executor;\r\n    private static CompletableFuture<Integer> hoge;\r\n    private static CompletableFuture<Integer> fuga;\r\n    private static CompletableFuture<Integer> chome;\r\n    private static CompletableFuture<Void> doAllWorks;\r\n\r\n    public static void main(String[] args) {\r\n\r\n        int procs = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();\r\n        if (procs < 3) {\r\n            procs = 3;\r\n        }\r\n\r\n        executor = Executors.newFixedThreadPool(procs);\r\n\r\n        hoge = CompletableFuture.supplyAsync(() -> works.countHoge(), executor);\r\n        fuga = CompletableFuture.supplyAsync(() -> works.countFuga(), executor);\r\n        chome = CompletableFuture.supplyAsync(() -> works.countChome(), executor);\r\n        doAllWorks = CompletableFuture.allOf(hoge, fuga, chome);\r\n\r\n        workCompletableFutures();\r\n\r\n        try {\r\n            System.out.println(hoge.get());\r\n        } catch (ExecutionException | InterruptedException ex) {\r\n            Logger.getLogger(TryCompletableFuture.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n        \r\n        try {\r\n            System.out.println(fuga.get());\r\n        } catch (InterruptedException | ExecutionException ex) {\r\n            Logger.getLogger(TryCompletableFuture.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n        \r\n        try {\r\n            System.out.println(chome.get());\r\n        } catch (InterruptedException | ExecutionException ex) {\r\n            Logger.getLogger(TryCompletableFuture.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n\r\n        CompletableFuture<String> monad = hoge.thenApply(r -> r * r * Math.PI).thenApply(Object::toString);  \r\n        try {\r\n            System.out.println(\"monad = \" + monad.get());\r\n        } catch (InterruptedException | ExecutionException ex) {\r\n            Logger.getLogger(TryCompletableFuture.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n        \r\n        while (true) {\r\n            if (doAllWorks.isDone()) {\r\n                System.out.println(\"executor.shutdown()\");\r\n                executor.shutdown();\r\n                try {\r\n                    if (!executor.awaitTermination(20, TimeUnit.SECONDS)) {\r\n                        System.out.println(\"executor.shutdownNow()\");\r\n                        executor.shutdownNow();\r\n                        break;\r\n                    }\r\n                } catch (InterruptedException ex) {\r\n                    Logger.getLogger(TryCompletableFuture.class.getName()).log(Level.SEVERE, null, ex);\r\n                    executor.shutdownNow();\r\n                    break;\r\n                }\r\n                break;\r\n            }\r\n        }\r\n    }\r\n\r\n    private static void workCompletableFutures() {\r\n\r\n        long startTime = System.nanoTime();\r\n\r\n        System.out.println(\"<---  START  --->\");\r\n\r\n        doAllWorks.thenRun(() -> {\r\n            try {\r\n                if ((hoge.get() + fuga.get() + chome.get()) == 11) {\r\n                    System.out.println(\"<---  DONE  --->\");\r\n                } else {\r\n                    System.out.println(\"<---  ERROR  --->\");\r\n                }\r\n            } catch (ExecutionException | InterruptedException e) {\r\n                throw new RuntimeException(e);\r\n            }\r\n\r\n            long time = System.nanoTime() - startTime;\r\n            System.out.println(\"\u51e6\u7406\u6642\u9593\u306f\u3001\"\r\n                    + (int) (time * 1e-9) \/ 3_600 + \"\u6642\u9593\"\r\n                    + (int) ((time * 1e-9) \/ 60) % 60 + \"\u5206\"\r\n                    + (int) (time * 1e-9 % 60) + \"\u79d2\"\r\n                    + Double.toString((time * 1e-9 % 60) % 1).substring(2));\r\n        });\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u51fa\u529b\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;&#8212;\u00a0 START\u00a0 &#8212;&gt;<br \/>\n1<br \/>\n3<br \/>\n7<br \/>\n&lt;&#8212;\u00a0 DONE\u00a0 &#8212;&gt;<br \/>\n\u51e6\u7406\u6642\u9593\u306f\u30010\u6642\u95930\u52066\u79d29916577070000008<br \/>\nmonad = 3.141592653589793<br \/>\nexecutor.shutdown()<\/p>\n<p>&nbsp;<\/p>\n<p>\u51e6\u7406\u6642\u9593\u304b\u3089\u305d\u308c\u305e\u308c\u306e\u51e6\u7406\u304c\u5e73\u884c\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u89e3\u308a\u307e\u3059\u306d\u3002(^_^)<\/p>\n<p>\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2013\/07\/p1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;\" title=\"p1\" alt=\"p1\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2013\/07\/p1_thumb.png\" width=\"437\" height=\"216\" border=\"0\" \/><\/a><\/p>\n<p>thenRun() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3068\u4e0a\u8a18\u306e\u3088\u3046\u306a\u7d50\u679c\u3068\u306a\u308a\u307e\u3059\u304c<\/p>\n<p>thenRunAsync() \u30e1\u30bd\u30c3\u30c9\u3068\u3044\u3046\u3082\u306e\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u00a0 ForkJoinPool.commonPool() \u3092\u4f7f\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u82e5\u5e72 thenRun() \u30e1\u30bd\u30c3\u30c9\u3068\u52d5\u4f5c\u304c\u9055\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3061\u3089\u306f\u30e1\u30bd\u30c3\u30c9\u5185\u306e\u51e6\u7406\u304c ExecutorService \u306b\u5168\u3066\u4e57\u3089\u306a\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u767b\u9332\u3055\u308c\u305f\u30bf\u30b9\u30af\u304c\u7d42\u4e86\u3057\u305f\u6642\u70b9\u3067 shutdown \u958b\u59cb\u3059\u308b\u3068shutdown \u958b\u59cb\u307e\u3067\u306b ExecutorService \u306b\u4e57\u3063\u3066\u3044\u308c\u3070\u5f53\u7136\u51e6\u7406\u3055\u308c\u308b\u306e\u3067\u3059\u304c\u30bf\u30a4\u30df\u30f3\u30b0\u304c\u60aa\u3044\u3068\u9593\u306b\u5408\u308f\u305a\u672a\u51e6\u7406\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>37 \u884c\u76ee\u304b\u3089 60 \u884c\u76ee\u306e\u8a08\u7b97\u7d50\u679c\u53d6\u5f97\u51e6\u7406\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u305d\u308c\u305e\u308c\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u826f\u304f\u89e3\u308a\u307e\u3059\u3002<\/p>\n<p>thenRun() \u30e1\u30bd\u30c3\u30c9\u306e\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u5168\u3066\u5b9f\u884c\u3055\u308c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;&#8212;\u00a0 START\u00a0 &#8212;&gt;<br \/>\n&lt;&#8212;\u00a0 DONE\u00a0 &#8212;&gt;<br \/>\nexecutor.shutdown()<br \/>\n\u51e6\u7406\u6642\u9593\u306f\u30010\u6642\u95930\u52066\u79d29965874390000007<\/p>\n<p>&nbsp;<\/p>\n<p>thenRunAsync() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u4e00\u90e8\u51e6\u7406\u3055\u308c\u305a\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u7d42\u4e86\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;&#8212;\u00a0 START\u00a0 &#8212;&gt;<br \/>\nexecutor.shutdown()<br \/>\n&lt;&#8212;\u00a0 DONE\u00a0 &#8212;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>\u3053\u306e\u3042\u305f\u308a\u306f\u5fae\u5999\u306b\u9055\u3046\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u306d\u3002<\/p>\n<p>\u3064\u3044\u3067\u306b\u3001thenRunAsync() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3067\u307f\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>ForkJoinPool.commonPool() \u304c\u5b58\u5728\u3057\u3066\u307e\u3059\u306d\u3002<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2013\/07\/p2.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;\" title=\"p2\" alt=\"p2\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2013\/07\/p2_thumb.png\" width=\"435\" height=\"231\" border=\"0\" \/><\/a><\/p>\n<p>\u3053\u308c\u3089\u306e\u4f7f\u3044\u5206\u3051\u306e\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f3\u304c\u601d\u3044\u3064\u304d\u307e\u305b\u3093\u3002(^_^;)<\/p>\n<p>\u3055\u3066\u3001\u6642\u9593\u306e\u304b\u304b\u308b\u51e6\u7406\u3092\u3059\u308b\u306e\u306f\u3044\u3044\u3051\u3069\u3042\u307e\u308a\u306b\u3082\u6642\u9593\u304c\u304b\u304b\u308a\u3059\u304e\u305f\u5834\u5408\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3088\u306d\u3002<\/p>\n<p>\u305d\u3093\u306a\u6642\u306e\u305f\u3081\u306b get(long timeout, TimeUnit unit) \u30e1\u30bd\u30c3\u30c9\u3068 complete(T value) \u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre title=\"TryCompletableFuture.java\"start-line=\"35\">\r\n        workCompletableFutures();\r\n        \r\n        try {\r\n            System.out.println(fuga.get(2, TimeUnit.SECONDS));\r\n        } catch (InterruptedException | ExecutionException | TimeoutException ex) {\r\n            Logger.getLogger(TryCompletableFuture.class.getName()).log(Level.SEVERE, null, ex);\r\n            fuga.complete(99);\r\n        }\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>fuga.get(2, TimeUnit.SECONDS) 2 \u79d2\u3067\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u3066 fuga.complete(99) \u3067 fuga \u306b 99 \u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u4f8b\u5916\u3082\u30b9\u30ed\u30fc\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3066\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;&#8212;\u00a0 START\u00a0 &#8212;&gt;<br \/>\n1<br \/>\n99<br \/>\n7 08, 2013 12:13:28 \u5348\u524d jp.yucchi.trycompletablefuture.TryCompletableFuture main<br \/>\nSEVERE: null<br \/>\njava.util.concurrent.TimeoutException<br \/>\nat java.util.concurrent.CompletableFuture.timedAwaitDone(CompletableFuture.java:376)<br \/>\nat java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1555)<br \/>\nat jp.yucchi.trycompletablefuture.TryCompletableFuture.main(TryCompletableFuture.java:39)<\/p>\n<p>&lt;&#8212;\u00a0 ERROR\u00a0 &#8212;&gt;<br \/>\n7<br \/>\n\u51e6\u7406\u6642\u9593\u306f\u30010\u6642\u95930\u52066\u79d29896285360000006<br \/>\nmonad = 3.141592653589793<br \/>\nexecutor.shutdown()<\/p>\n<p>&nbsp;<\/p>\n<p>\u3061\u3083\u3093\u3068\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u3066\u4f8b\u5916\u3092\u6295\u3052\u3066\u305d\u3057\u3066 fuga \u306b 99 \u3092\u30bb\u30c3\u30c8\u3057\u3066\u307e\u3059\u306d\u3002<\/p>\n<p>fuga \u306e\u5024\u304c 99 \u306b\u306a\u308b\u3053\u3068\u306b\u3088\u3063\u3066 hoge, fuga, chome \u306e\u5408\u8a08\u5024\u304c 11 \u3068\u7b49\u3057\u304f\u306a\u3089\u306a\u3044\u306e\u3067 &lt;&#8212;\u00a0 ERROR\u00a0 &#8212;&gt; \u3068\u5224\u5b9a\u3055\u308c\u51fa\u529b\u3055\u308c\u3066\u307e\u3059\u3002<\/p>\n<p>\u3082\u3046\u3001ExecutorService\u3001 Callable\u3001Future \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9 \u306e\u6642\u4ee3\u306f\u30aa\u30ef\u30b3\u30f3\u304b\u306a\uff1f<\/p>\n<p>\u3056\u3063\u3068\u78ba\u8a8d\u3057\u305f\u3051\u3069\u9593\u9055\u3063\u3066\u308b\u53ef\u80fd\u6027\u304c\u9ad8\u3044\u306e\u3067\u65e5\u672c\u8a9e\u3067\u8ab0\u304b\u304c\u8a73\u3057\u304f\u89e3\u8aac\u3057\u3066\u304f\u308c\u308b\u306e\u3092\u5f85\u3064\u3068\u3057\u307e\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u304b\u306a\u308a CompletableFuture \u3063\u3066\u3044\u3051\u3066\u308b\u6c17\u304c\u3057\u307e\u3059\uff01<\/p>\n<p><span style=\"color: #0000ff; font-size: large;\"><strong>Java8 \u65e9\u304f\u30ea\u30ea\u30fc\u30b9\u3057\u3066\u304a\u304f\u308c\uff01<\/strong><\/span><\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2013\/07\/cludia_2013_07_08_001.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;\" title=\"cludia_2013_07_08_001\" alt=\"cludia_2013_07_08_001\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2013\/07\/cludia_2013_07_08_001_thumb.png\" width=\"838\" height=\"600\" border=\"0\" \/><\/a><\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6cde1685-f218-4e16-b24b-832d1cf2f118\" style=\"margin: 0px; padding: 0px; float: none; display: inline;\">Hatena \u30bf\u30b0: <a href=\"http:\/\/b.hatena.ne.jp\/t\/Java\" rel=\"tag\">Java<\/a><\/div>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_hatena\"><a href='\/\/b.hatena.ne.jp\/add?mode=confirm&url=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D1096&title=CompletableFuture%20%E3%82%92%E8%A7%A3%E3%82%89%E3%81%AA%E3%81%84%E3%81%BE%E3%81%BE%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/hatena.gif' alt='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' width='16' height='12' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D1096&t=CompletableFuture%20%E3%82%92%E8%A7%A3%E3%82%89%E3%81%AA%E3%81%84%E3%81%BE%E3%81%BE%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"http:\/\/yucchi.jp\/blog\/?p=1096\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/yucchi.jp\/blog\/?p=1096\" data-text=\"CompletableFuture \u3092\u89e3\u3089\u306a\u3044\u307e\u307e\u8a66\u3057\u3066\u307f\u305f\" data-lang=\"ja\">Tweet<\/a><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Java8 \u306e\u76ee\u7389\u6a5f\u80fd\u306f\u4e26\u884c\u51e6\u7406\u3092\u5bb9\u6613\u306b\u3059\u308b\u305f\u3081\u306b\u63a1\u7528\u3055\u308c\u305f Lambda \u306b\u6ce8\u76ee\u304c\u96c6\u307e\u3063\u3066\u307e\u3059\u3002 \u305d\u306e\u4ed6\u306b\u3082\u4fbf\u5229\u306a\u6a5f\u80fd\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u4f55\u6545\u304b\u4eba\u6c17\u306e\u7121\u3044\uff1f CompletableFuture \u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u3053\u308c\u3082\u5916\u56fd\u8a9e\u306e\u30b5\u30a4\u30c8\u304b\u3089\u306e\u60c5\u5831\u3092\u5143\u306b\u89e3\u3089\u306a\u3044\u307e\u307e\u30b4\u30cb\u30e7\u30b4\u30cb\u30e7\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u3061\u306a\u307f\u306b CompletableFuture \u306e\u60c5\u5831\u306f\u30b0\u30fc\u30b0\u30eb\u5148\u751f\u306b\u805e\u3044\u3066\u307f\u3066\u3082\u65b0\u3057\u3044\u60c5\u5831\u306f\u6570\u4ef6\u3057\u304b\u30d2\u30c3\u30c8\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002 \u8ab0\u304b\u304c\u65e5\u672c\u8a9e\u3067\u512a\u3057\u304f\u89e3\u8aac\u3057\u3066\u304f\u308c\u308b\u306e\u3092\u5f85\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c Lambda \u306e\u4eba\u6c17\u306e\u9ad8\u3055\u304b\u3089\u304b\u898b\u5411\u304d\u3082\u3055\u308c\u306a\u3044\u53ef\u611b\u305d\u3046\u306a\u5b50\u3068\u306a\u3063\u3066\u307e\u3059\u3002\uff08\u30f2\u30d2 CompletableFuture \u3063\u3066\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[17],"class_list":["post-1096","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"_links":{"self":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1096"}],"version-history":[{"count":3,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1096\/revisions"}],"predecessor-version":[{"id":1098,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1096\/revisions\/1098"}],"wp:attachment":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1096"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}