{"id":467719,"date":"2025-07-19T09:00:10","date_gmt":"2025-07-19T09:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=467719"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=467719","title":{"rendered":"<span>\u0412\u0440\u0435\u0434\u043d\u044b\u0435 \u0441\u043e\u0432\u0435\u0442\u044b Java: \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 Parallel Stream<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0412\u00a0\u0435\u0436\u0435\u0433\u043e\u0434\u043d\u044b\u0445 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430\u00a0\u0432\u043e\u043f\u0440\u043e\u0441 \u00ab\u043a\u0430\u043a\u00a0\u0436\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447 \u043d\u0430\u00a0Java\u00bb, \u044f \u0447\u0430\u0441\u0442\u0435\u043d\u044c\u043a\u043e \u043d\u0430\u0442\u044b\u043a\u0430\u044e\u0441\u044c \u043d\u0430\u00a0\u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Stream API.<\/p>\n<p>\u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u00a0\u0442\u043e\u043c \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Parallel Stream \u0438 \u0433\u0434\u0435 \u043e\u043d \u0434\u0430\u0441\u0442 \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0432\u00a0\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. <a href=\"https:\/\/habr.com\/ru\/articles\/745332\/\" rel=\"noopener noreferrer nofollow\">\u0425\u0430\u0431\u0440<\/a> \u0438 <a href=\"https:\/\/www.baeldung.com\/java-when-to-use-parallel-stream\" rel=\"noopener noreferrer nofollow\">Baeldung <\/a>\u043f\u043b\u043e\u0445\u043e\u0433\u043e \u043d\u0435\u00a0\u043f\u043e\u0441\u043e\u0432\u0435\u0442\u0443\u044e\u0442. \u0418 \u0432\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e\u00a0\u2014 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u00a0Parallel Stream \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u0435. \u0422\u0430\u043a \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u0437\u0430\u0434\u0435\u0448\u0435\u0432\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<pre><code class=\"java\">List&lt;Runnable&gt; tasks = generateExpansiveTasks(); tasks.stream().parallel().forEach(Runnable::run);<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451! \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0442\u0435\u0431\u0435 ExecutorService#invokeAll \u0438 join&#8217;\u0430 \u043a\u00a0Future \u0438\u043b\u0438\u00a0Future#get \u0441\u00a0\u0435\u0433\u043e InterruptedException. \u0414\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u0447\u0438\u0442\u0430\u0435\u043c\u043e. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c\u00a0\u0431\u044b, \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u043b\u0430\u043d, \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u043a\u0430\u043a\u00a0\u0448\u0432\u0435\u0439\u0446\u0430\u0440\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u044b. \u041d\u043e\u00a0\u0437\u0430\u043a\u043e\u043d \u041c\u0451\u0440\u0444\u0438 \u043d\u0438\u043a\u0442\u043e \u043d\u0435\u00a0\u043e\u0442\u043c\u0435\u043d\u044f\u043b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u00a0\u0432\u0441\u0451 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435\u00a0\u0442\u0430\u043a.<\/p>\n<pre><code class=\"java\">AtomicInteger callsCounter = new AtomicInteger(); List&lt;Runnable&gt; tasks = IntStream.range(0, 100)   .&lt;Runnable&gt;mapToObj(taskNumber -&gt; () -&gt; {     if (callsCounter.incrementAndGet() &gt;= 10) {         throw new RuntimeException();     }     try {         Thread.sleep(1); \/\/ simulate intensive work     } catch (InterruptedException e) {         System.err.println(\"!INTERRUPTED!\");         throw new IllegalStateException(e);     } }).toList(); try {     tasks.stream().parallel().forEach(Runnable::run); } catch (Exception ignore) { } System.out.println(callsCounter);<\/code><\/pre>\n<p>\u0412\u00a0sequential \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0451 \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u00a0\u2014 callsCounter \u0437\u0430\u043c\u0440\u0451\u0442 \u043d\u0430\u00a0\u043e\u0442\u043c\u0435\u0442\u043a\u0435 10. \u0412\u00a0\u0441\u043b\u0443\u0447\u0430\u0435 parallel\u00a0\u2014 \u043a\u0430\u043a\u00a0\u043f\u043e\u0432\u0435\u0437\u0451\u0442. \u041c\u043e\u0436\u0435\u0442 77, \u043c\u043e\u0436\u0435\u0442 42. \u041d\u043e\u00a0\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438 \u043a\u00a0\u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u00a0\u0431\u044b\u043b\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u00a0\u2014 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0435\u0441\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 10\u00a0\u0437\u0430\u0434\u0430\u0447 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0442\u043e callsCounter \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 10. \u041d\u043e\u00a0\u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u0430\u043b\u043e! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u00a0callsCounter \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 2\u00a0\u0440\u0430\u0437\u0430:<\/p>\n<pre><code class=\"java\">int check1 = 0, check2 = 0; while (check1 == check2) {     AtomicInteger callsCounter = new AtomicInteger();     List&lt;Runnable&gt; tasks = IntStream.range(0, 100)             .&lt;Runnable&gt;mapToObj(taskNumber -&gt; () -&gt; {                 if (callsCounter.incrementAndGet() &gt;= 10) {                     throw new RuntimeException();                 }                 try {                     Thread.sleep(1); \/\/ simulate intensive work                 } catch (InterruptedException e) {                     System.err.println(\"!INTERRUPTED!\");                     throw new IllegalStateException(e);                 }             }).toList();     try {         tasks.stream().parallel().forEach(Runnable::run);     } catch (Exception ignore) {     }     check1 = callsCounter.get();     ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.SECONDS);     check2 = callsCounter.get();     System.out.println(\"First: \" + check1);     System.out.println(\"Second: \" + check2); }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043f\u043e\u0440\u0430 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0Parallel Stream \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u00a0common ForkJoinPool. \u0415\u0441\u043b\u0438\u00a0\u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u0435\u0435, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/ForkJoinTask.html#fork--\" rel=\"noopener noreferrer nofollow\">ForkJoinTask#fork<\/a> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 pool \u0432\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u00a0\u043f\u043e\u0442\u043e\u043a\u0430, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e. \u0412\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u0438\u00a0\u043f\u043e\u043c\u043e\u0449\u0438 awaitQuiescence \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u00a0common ForkJoinPool \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b. \u0412\u00a0\u043a\u0430\u043a\u043e\u0439\u2011\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0\u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041d\u0430\u043c\u043d\u043e\u0433\u043e \u0447\u0430\u0449\u0435 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0435\u00a0\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u00a0\u0441\u043e\u043d.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">int check1 = 0, check2 = 0; while (check1 == check2) {     AtomicInteger callsCounter = new AtomicInteger();     Thread main = Thread.currentThread();     AtomicBoolean exceptionCaught = new AtomicBoolean();     List&lt;Runnable&gt; tasks = IntStream.range(0, 100)             .&lt;Runnable&gt;mapToObj(taskNumber -&gt; () -&gt; {                 if (exceptionCaught.get()) {                     System.out.println(\"EXECUTED AFTER EXCEPTION CAUGHT IN CALLER THREAD\");                 }                 if (callsCounter.incrementAndGet() &gt;= 10) {                     throw new RuntimeException();                 }                 int pause = Thread.currentThread() == main? 0 : 10;                 try {                     Thread.sleep(pause); \/\/ simulate intensive work                 } catch (InterruptedException e) {                     System.err.println(\"!INTERRUPTED!\");                     throw new IllegalStateException(e);                 }             }).toList();     try {         tasks.stream().parallel().forEach(Runnable::run);     } catch (Exception ignore) {         exceptionCaught.set(true);     }     check1 = callsCounter.get();     ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.SECONDS);     check2 = callsCounter.get();     System.out.println(\"First: \" + check1);     System.out.println(\"Second: \" + check2); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412\u00a0\u0441\u0443\u0445\u043e\u043c \u043e\u0441\u0442\u0430\u0442\u043a\u0435, \u0435\u0441\u043b\u0438 \u043e\u0434\u043d\u0430 \u0438\u0437\u00a0\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u00a0\u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u0431\u0440\u043e\u0441\u0438\u043b\u0430 Exception, \u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443, \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0443\u0436\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0451 \u0435\u0449\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u0432\u00a0\u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435\u00a0\u0441\u0434\u0435\u043b\u0430\u044e\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e. \u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u043e\u0445\u043d\u0443\u0442\u044c. \u0412\u0441\u0435 \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e? \u041d\u0435\u00a0\u0441\u043e\u0432\u0441\u0435\u043c. \u0423\u0433\u0430\u0434\u0430\u0439\u0442\u0435 \u043a\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0434\u043b\u044f\u00a0\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<pre><code class=\"java\">public class Main {     public static void main(String[] args) throws Exception {         assert ForkJoinPool.getCommonPoolParallelism() == 8;         System.out.println(ForkJoinPool.commonPool());         List&lt;Integer&gt; sleepMillis = IntStream.range(0, 98).boxed()           .collect(toCollection(ArrayList::new));         sleepMillis.add(1000);         sleepMillis.add(2000);         Instant start = Instant.now();         sleepMillis.stream().parallel().forEach(Main::sleepMillis);         System.out.println(\"Parallel stream took:\" + Duration.between(start, Instant.now()));         ExecutorService es = Executors.newFixedThreadPool(8);         start = Instant.now();         sleepMillis.stream()                 .&lt;Runnable&gt;map(num -&gt; () -&gt; sleepMillis(num))                 .forEach(es::execute);         es.shutdown();         es.awaitTermination(1, TimeUnit.DAYS);         System.out.println(\"Executor service took:\" + Duration.between(start, Instant.now()));     }      private static void sleepMillis(int ms) {         try {             Thread.sleep(ms);         } catch (InterruptedException e) {             throw new IllegalStateException(e);         }     } }<\/code><\/pre>\n<p>\u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u00a0\u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u043e\u00a0\u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e. \u0418\u043b\u0438\u00a0\u0434\u0430\u0436\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0432\u00a0\u0441\u043b\u0443\u0447\u0430\u0435 Parallel Stream, \u0432\u0435\u0434\u044c \u0442\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 main \u043f\u043e\u0442\u043e\u043a. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u00a0\u0434\u0435\u043b\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<\/p>\n<blockquote>\n<p>Parallel stream took:PT3.4147801S<br \/>Executor service took:PT2.5742424S<\/p>\n<\/blockquote>\n<p>\u0414\u0435\u043b\u043e \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0Parrallel Stream \u0431\u0435\u0440\u0435\u0442 \u0437\u0430\u00a0\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u0440\u0435\u0442 \u043d\u0435\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 consumer#accept, \u0430\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0430\u0434 \u0447\u0430\u0441\u0442\u044c\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u0414\u0435\u0442\u0430\u043b\u044c\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0435 <a href=\"https:\/\/github.com\/openjdk\/jdk\/blob\/dfacda488bfbe2e11e8d607a6d08527710286982\/src\/java.base\/share\/classes\/java\/util\/stream\/ForEachOps.java\" rel=\"noopener noreferrer nofollow\">java.util.stream.ForEachOps<\/a> \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 2\u00a0\u0441\u0430\u043c\u044b\u0435 \u0434\u043e\u043b\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u00a0\u043e\u0434\u043d\u043e\u043c thread&#8217;\u0435. \u0412\u00a0\u043a\u0430\u043a\u043e\u0439\u2011\u0442\u043e \u043c\u0435\u0440\u0435 \u044d\u0442\u043e\u0442 \u0430\u0441\u043f\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0438\u0432\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u00a0\u0441\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f random shuffle.<\/p>\n<p>\u0423\u0432\u044b, \u043d\u043e\u00a0\u0438 \u044d\u0442\u043e \u043d\u0435\u00a0\u0432\u0441\u0451. \u0414\u043e\u043b\u0433\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c common ForkJoinPool. \u0414\u043b\u044f\u00a0\u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u00a0\u043a\u0430\u043a\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0common Pool \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u00a0async \u043c\u0435\u0442\u043e\u0434\u0430\u0445 <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/CompletableFuture.html\" rel=\"noopener noreferrer nofollow\">CompletableFuture<\/a>, \u0435\u0441\u043b\u0438 executor \u043d\u0435\u00a0\u0443\u043a\u0430\u0437\u0430\u043d \u044f\u0432\u043d\u043e. \u0414\u043b\u044f\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"java\">private static Duration measureCompletableFutureAsyncDelay() {     CompletableFuture&lt;Long&gt; cf = new CompletableFuture&lt;&gt;();     CompletableFuture&lt;Duration&gt; asyncStage = cf             .thenApplyAsync(start -&gt; Duration.ofNanos(System.nanoTime() - start));     long completionStartTime = System.nanoTime();     cf.complete(completionStartTime);     return asyncStage.join(); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 common pool \u043d\u0435\u00a0\u0437\u0430\u043d\u044f\u0442, \u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f thenApplyAsync callback&#8217;\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043e \u043d\u0430\u00a0\u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0442\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434 \u0434\u043e\u00a0\u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434. \u041d\u043e\u00a0\u0435\u0441\u043b\u0438 common pool \u0437\u0430\u043d\u044f\u0442, \u0434\u043e\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f *Async callback&#8217;\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class Main {   public static void main(String[] args) throws Exception {     int pp = Integer.parseInt(System.getProperty(\"java.util.concurrent.ForkJoinPool.common.parallelism\", \"-1\"));     int expectedPp = 2;     if (pp != expectedPp) {       System.err.println(\"Please restart with -Djava.util.concurrent.ForkJoinPool.common.parallelism=\" + expectedPp);       throw new IllegalStateException(\"BAD PARALLELISM\");     }     System.out.println(\"First completable callback future delay: \" + measureCompletableFutureAsyncDelay());     System.out.println(\"Second completable callback future delay: \" + measureCompletableFutureAsyncDelay());     CountDownLatch fjpExhausted = new CountDownLatch(pp);     Future&lt;Duration&gt; streamDuration = startLongTasksInParallelStream(fjpExhausted);     fjpExhausted.await();     System.out.println(\"Third completable callback future delay: \" + measureCompletableFutureAsyncDelay());     System.out.println(\"Stream duration: \" + streamDuration.get());   }    private static Duration measureCompletableFutureAsyncDelay() {     CompletableFuture&lt;Long&gt; cf = new CompletableFuture&lt;&gt;();     CompletableFuture&lt;Duration&gt; asyncStage = cf         .thenApplyAsync(start -&gt; Duration.ofNanos(System.nanoTime() - start));     long completionStartTime = System.nanoTime();     cf.complete(completionStartTime);     return asyncStage.join();   }    private static Future&lt;Duration&gt; startLongTasksInParallelStream(CountDownLatch fjpExhausted) {     ThreadFactory tf = Executors.defaultThreadFactory();     ThreadFactory dtf = runnable -&gt; {       Thread thread = tf.newThread(runnable);       thread.setDaemon(true);       return thread;     };     ExecutorService service = Executors.newSingleThreadExecutor(dtf);     Future&lt;Duration&gt; res = service.submit(() -&gt; {       long startTime = System.nanoTime();       IntStream.range(0, 100).parallel().forEach(num -&gt; {         if (Thread.currentThread() instanceof ForkJoinWorkerThread) {           fjpExhausted.countDown();         }         expensiveProcess(num);       });       return Duration.ofNanos(System.nanoTime() - startTime);     });     service.shutdown();     return res;   }    private static void expensiveProcess(Object unusedArg) {     try {       Thread.sleep(1000); \/\/simulate hard IO\/blocking work     } catch (Exception e) {       throw new IllegalStateException(e);     }   } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412\u00a0\u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u0441\u0442\u044b\u043b\u0438 \u0432\u00a0\u0432\u0438\u0434\u0435 <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/ForkJoinPool.html#managedBlock-java.util.concurrent.ForkJoinPool.ManagedBlocker-\" rel=\"noopener noreferrer nofollow\">ForkJoinPool#managedBlock<\/a> \u0434\u043b\u044f\u00a0\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u00a0Parallel Stream, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f&#8230;<\/p>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 Parallel Stream, \u0435\u0441\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0432\u044b \u0438\u0449\u0438\u0442\u0435 \u0441\u0435\u0440\u0435\u0431\u0440\u044f\u043d\u0443\u044e \u043f\u0443\u043b\u044e;<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b \u043d\u0435\u00a0\u0445\u043e\u0442\u0438\u0442\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043f\u0440\u0438\u00a0\u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0432\u0435\u0434\u044c \u0442\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430\u00a0\u043f\u0440\u043e\u0434\u0435 \u043a\u0430\u043a\u0438\u0435 side effect&#8217;\u044b \u0443\u0441\u043f\u0435\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434;<\/p>\n<\/li>\n<li>\n<p>\u0432\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c common ForkJoinPool \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u00a0\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u043a\u043e\u043d\u0435\u0447\u043d\u043e:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7b5\/b8e\/ffe\/7b5b8effe3b279f8915e29a94c91ce19.png\" alt=\"\u041d\u0430\u0440\u043e\u0434\u043d\u0430\u044f \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u044c. Image by Kandinsky AI 4.1.\" title=\"\u041d\u0430\u0440\u043e\u0434\u043d\u0430\u044f \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u044c. Image by Kandinsky AI 4.1.\" width=\"1280\" height=\"731\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/7b5\/b8e\/ffe\/7b5b8effe3b279f8915e29a94c91ce19.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7b5\/b8e\/ffe\/7b5b8effe3b279f8915e29a94c91ce19.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041d\u0430\u0440\u043e\u0434\u043d\u0430\u044f \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u044c. Image by Kandinsky AI 4.1.<\/figcaption><\/div>\n<\/figure>\n<p><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><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\/ru\/articles\/929120\/\"> https:\/\/habr.com\/ru\/articles\/929120\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0412\u00a0\u0435\u0436\u0435\u0433\u043e\u0434\u043d\u044b\u0445 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430\u00a0\u0432\u043e\u043f\u0440\u043e\u0441 \u00ab\u043a\u0430\u043a\u00a0\u0436\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447 \u043d\u0430\u00a0Java\u00bb, \u044f \u0447\u0430\u0441\u0442\u0435\u043d\u044c\u043a\u043e \u043d\u0430\u0442\u044b\u043a\u0430\u044e\u0441\u044c \u043d\u0430\u00a0\u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Stream API.<\/p>\n<p>\u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u00a0\u0442\u043e\u043c \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Parallel Stream \u0438 \u0433\u0434\u0435 \u043e\u043d \u0434\u0430\u0441\u0442 \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0432\u00a0\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. <a href=\"https:\/\/habr.com\/ru\/articles\/745332\/\" rel=\"noopener noreferrer nofollow\">\u0425\u0430\u0431\u0440<\/a> \u0438 <a href=\"https:\/\/www.baeldung.com\/java-when-to-use-parallel-stream\" rel=\"noopener noreferrer nofollow\">Baeldung <\/a>\u043f\u043b\u043e\u0445\u043e\u0433\u043e \u043d\u0435\u00a0\u043f\u043e\u0441\u043e\u0432\u0435\u0442\u0443\u044e\u0442. \u0418 \u0432\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e\u00a0\u2014 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u00a0Parallel Stream \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u0435. \u0422\u0430\u043a \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u0437\u0430\u0434\u0435\u0448\u0435\u0432\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<pre><code class=\"java\">List&lt;Runnable&gt; tasks = generateExpansiveTasks(); tasks.stream().parallel().forEach(Runnable::run);<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451! \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0442\u0435\u0431\u0435 ExecutorService#invokeAll \u0438 join&#8217;\u0430 \u043a\u00a0Future \u0438\u043b\u0438\u00a0Future#get \u0441\u00a0\u0435\u0433\u043e InterruptedException. \u0414\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u0447\u0438\u0442\u0430\u0435\u043c\u043e. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c\u00a0\u0431\u044b, \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u043b\u0430\u043d, \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u043a\u0430\u043a\u00a0\u0448\u0432\u0435\u0439\u0446\u0430\u0440\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u044b. \u041d\u043e\u00a0\u0437\u0430\u043a\u043e\u043d \u041c\u0451\u0440\u0444\u0438 \u043d\u0438\u043a\u0442\u043e \u043d\u0435\u00a0\u043e\u0442\u043c\u0435\u043d\u044f\u043b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u00a0\u0432\u0441\u0451 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435\u00a0\u0442\u0430\u043a.<\/p>\n<pre><code class=\"java\">AtomicInteger callsCounter = new AtomicInteger(); List&lt;Runnable&gt; tasks = IntStream.range(0, 100)   .&lt;Runnable&gt;mapToObj(taskNumber -&gt; () -&gt; {     if (callsCounter.incrementAndGet() &gt;= 10) {         throw new RuntimeException();     }     try {         Thread.sleep(1); \/\/ simulate intensive work     } catch (InterruptedException e) {         System.err.println(\"!INTERRUPTED!\");         throw new IllegalStateException(e);     } }).toList(); try {     tasks.stream().parallel().forEach(Runnable::run); } catch (Exception ignore) { } System.out.println(callsCounter);<\/code><\/pre>\n<p>\u0412\u00a0sequential \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0451 \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u00a0\u2014 callsCounter \u0437\u0430\u043c\u0440\u0451\u0442 \u043d\u0430\u00a0\u043e\u0442\u043c\u0435\u0442\u043a\u0435 10. \u0412\u00a0\u0441\u043b\u0443\u0447\u0430\u0435 parallel\u00a0\u2014 \u043a\u0430\u043a\u00a0\u043f\u043e\u0432\u0435\u0437\u0451\u0442. \u041c\u043e\u0436\u0435\u0442 77, \u043c\u043e\u0436\u0435\u0442 42. \u041d\u043e\u00a0\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438 \u043a\u00a0\u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u00a0\u0431\u044b\u043b\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u00a0\u2014 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0435\u0441\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 10\u00a0\u0437\u0430\u0434\u0430\u0447 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0442\u043e callsCounter \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 10. \u041d\u043e\u00a0\u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u0430\u043b\u043e! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u00a0callsCounter \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 2\u00a0\u0440\u0430\u0437\u0430:<\/p>\n<pre><code class=\"java\">int check1 = 0, check2 = 0; while (check1 == check2) {     AtomicInteger callsCounter = new AtomicInteger();     List&lt;Runnable&gt; tasks = IntStream.range(0, 100)             .&lt;Runnable&gt;mapToObj(taskNumber -&gt; () -&gt; {                 if (callsCounter.incrementAndGet() &gt;= 10) {                     throw new RuntimeException();                 }                 try {                     Thread.sleep(1); \/\/ simulate intensive work                 } catch (InterruptedException e) {                     System.err.println(\"!INTERRUPTED!\");                     throw new IllegalStateException(e);                 }             }).toList();     try {         tasks.stream().parallel().forEach(Runnable::run);     } catch (Exception ignore) {     }     check1 = callsCounter.get();     ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.SECONDS);     check2 = callsCounter.get();     System.out.println(\"First: \" + check1);     System.out.println(\"Second: \" + check2); }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043f\u043e\u0440\u0430 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0Parallel Stream \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u00a0common ForkJoinPool. \u0415\u0441\u043b\u0438\u00a0\u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u0435\u0435, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/ForkJoinTask.html#fork--\" rel=\"noopener noreferrer nofollow\">ForkJoinTask#fork<\/a> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 pool \u0432\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u00a0\u043f\u043e\u0442\u043e\u043a\u0430, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e. \u0412\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u0438\u00a0\u043f\u043e\u043c\u043e\u0449\u0438 awaitQuiescence \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u00a0common ForkJoinPool \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b. \u0412\u00a0\u043a\u0430\u043a\u043e\u0439\u2011\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0\u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041d\u0430\u043c\u043d\u043e\u0433\u043e \u0447\u0430\u0449\u0435 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0435\u00a0\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u00a0\u0441\u043e\u043d.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">int check1 = 0, check2 = 0; while (check1 == check2) {     AtomicInteger callsCounter = new AtomicInteger();     Thread main = Thread.currentThread();     AtomicBoolean exceptionCaught = new AtomicBoolean();     List&lt;Runnable&gt; tasks = IntStream.range(0, 100)             .&lt;Runnable&gt;mapToObj(taskNumber -&gt; () -&gt; {                 if (exceptionCaught.get()) {                     System.out.println(\"EXECUTED AFTER EXCEPTION CAUGHT IN CALLER THREAD\");                 }                 if (callsCounter.incrementAndGet() &gt;= 10) {                     throw new RuntimeException();                 }                 int pause = Thread.currentThread() == main? 0 : 10;                 try {                     Thread.sleep(pause); \/\/ simulate intensive work                 } catch (InterruptedException e) {                     System.err.println(\"!INTERRUPTED!\");                     throw new IllegalStateException(e);                 }             }).toList();     try {         tasks.stream().parallel().forEach(Runnable::run);     } catch (Exception ignore) {         exceptionCaught.set(true);     }     check1 = callsCounter.get();     ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.SECONDS);     check2 = callsCounter.get();     System.out.println(\"First: \" + check1);     System.out.println(\"Second: \" + check2); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412\u00a0\u0441\u0443\u0445\u043e\u043c \u043e\u0441\u0442\u0430\u0442\u043a\u0435, \u0435\u0441\u043b\u0438 \u043e\u0434\u043d\u0430 \u0438\u0437\u00a0\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u00a0\u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u0431\u0440\u043e\u0441\u0438\u043b\u0430 Exception, \u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443, \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0443\u0436\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0451 \u0435\u0449\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u0432\u00a0\u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435\u00a0\u0441\u0434\u0435\u043b\u0430\u044e\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e. \u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u043e\u0445\u043d\u0443\u0442\u044c. \u0412\u0441\u0435 \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e? \u041d\u0435\u00a0\u0441\u043e\u0432\u0441\u0435\u043c. \u0423\u0433\u0430\u0434\u0430\u0439\u0442\u0435 \u043a\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0434\u043b\u044f\u00a0\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<pre><code class=\"java\">public class Main {     public static void main(String[] args) throws Exception {         assert ForkJoinPool.getCommonPoolParallelism() == 8;         System.out.println(ForkJoinPool.commonPool());         List&lt;Integer&gt; sleepMillis = IntStream.range(0, 98).boxed()           .collect(toCollection(ArrayList::new));         sleepMillis.add(1000);         sleepMillis.add(2000);         Instant start = Instant.now();         sleepMillis.stream().parallel().forEach(Main::sleepMillis);         System.out.println(\"Parallel stream took:\" + Duration.between(start, Instant.now()));         ExecutorService es = Executors.newFixedThreadPool(8);         start = Instant.now();         sleepMillis.stream()                 .&lt;Runnable&gt;map(num -&gt; () -&gt; sleepMillis(num))                 .forEach(es::execute);         es.shutdown();         es.awaitTermination(1, TimeUnit.DAYS);         System.out.println(\"Executor service took:\" + Duration.between(start, Instant.now()));     }      private static void sleepMillis(int ms) {         try {             Thread.sleep(ms);         } catch (InterruptedException e) {             throw new IllegalStateException(e);         }     } }<\/code><\/pre>\n<p>\u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u00a0\u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u043e\u00a0\u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e. \u0418\u043b\u0438\u00a0\u0434\u0430\u0436\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0432\u00a0\u0441\u043b\u0443\u0447\u0430\u0435 Parallel Stream, \u0432\u0435\u0434\u044c \u0442\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 main \u043f\u043e\u0442\u043e\u043a. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u00a0\u0434\u0435\u043b\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<\/p>\n<blockquote>\n<p>Parallel stream took:PT3.4147801S<br \/>Executor service took:PT2.5742424S<\/p>\n<\/blockquote>\n<p>\u0414\u0435\u043b\u043e \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0Parrallel Stream \u0431\u0435\u0440\u0435\u0442 \u0437\u0430\u00a0\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u0440\u0435\u0442 \u043d\u0435\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 consumer#accept, \u0430\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0430\u0434 \u0447\u0430\u0441\u0442\u044c\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u0414\u0435\u0442\u0430\u043b\u044c\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0435 <a href=\"https:\/\/github.com\/openjdk\/jdk\/blob\/dfacda488bfbe2e11e8d607a6d08527710286982\/src\/java.base\/share\/classes\/java\/util\/stream\/ForEachOps.java\" rel=\"noopener noreferrer nofollow\">java.util.stream.ForEachOps<\/a> \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 2\u00a0\u0441\u0430\u043c\u044b\u0435 \u0434\u043e\u043b\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u00a0\u043e\u0434\u043d\u043e\u043c thread&#8217;\u0435. \u0412\u00a0\u043a\u0430\u043a\u043e\u0439\u2011\u0442\u043e \u043c\u0435\u0440\u0435 \u044d\u0442\u043e\u0442 \u0430\u0441\u043f\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0438\u0432\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u00a0\u0441\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f random shuffle.<\/p>\n<p>\u0423\u0432\u044b, \u043d\u043e\u00a0\u0438 \u044d\u0442\u043e \u043d\u0435\u00a0\u0432\u0441\u0451. \u0414\u043e\u043b\u0433\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c common ForkJoinPool. \u0414\u043b\u044f\u00a0\u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u00a0\u043a\u0430\u043a\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0common Pool \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u00a0async \u043c\u0435\u0442\u043e\u0434\u0430\u0445 <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/CompletableFuture.html\" rel=\"noopener noreferrer nofollow\">CompletableFuture<\/a>, \u0435\u0441\u043b\u0438 executor \u043d\u0435\u00a0\u0443\u043a\u0430\u0437\u0430\u043d \u044f\u0432\u043d\u043e. \u0414\u043b\u044f\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"java\">private static Duration measureCompletableFutureAsyncDelay() {     CompletableFuture&lt;Long&gt; cf = new CompletableFuture&lt;&gt;();     CompletableFuture&lt;Duration&gt; asyncStage = cf             .thenApplyAsync(start -&gt; Duration.ofNanos(System.nanoTime() - start));     long completionStartTime = System.nanoTime();     cf.complete(completionStartTime);     return asyncStage.join(); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 common pool \u043d\u0435\u00a0\u0437\u0430\u043d\u044f\u0442, \u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f thenApplyAsync callback&#8217;\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043e \u043d\u0430\u00a0\u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0442\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434 \u0434\u043e\u00a0\u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434. \u041d\u043e\u00a0\u0435\u0441\u043b\u0438 common pool \u0437\u0430\u043d\u044f\u0442, \u0434\u043e\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f *Async callback&#8217;\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class Main {   public static void main(String[] args) throws Exception {     int pp = Integer.parseInt(System.getProperty(\"java.util.concurrent.ForkJoinPool.common.parallelism\", \"-1\"));     int expectedPp = 2;     if (pp != expectedPp) {       System.err.println(\"Please restart with -Djava.util.concurrent.ForkJoinPool.common.parallelism=\" + expectedPp);       throw new IllegalStateException(\"BAD PARALLELISM\");     }     System.out.println(\"First completable callback future delay: \" + measureCompletableFutureAsyncDelay());     System.out.println(\"Second completable callback future delay: \" + measureCompletableFutureAsyncDelay());     CountDownLatch fjpExhausted = new CountDownLatch(pp);     Future&lt;Duration&gt; streamDuration = startLongTasksInParallelStream(fjpExhausted);     fjpExhausted.await();     System.out.println(\"Third completable callback future delay: \" + measureCompletableFutureAsyncDelay());     System.out.println(\"Stream duration: \" + streamDuration.get());   }    private static Duration measureCompletableFutureAsyncDelay() {     CompletableFuture&lt;Long&gt; cf = new CompletableFuture&lt;&gt;();     CompletableFuture&lt;Duration&gt; asyncStage = cf         .thenApplyAsync(start -&gt; Duration.ofNanos(System.nanoTime() - start));     long completionStartTime = System.nanoTime();     cf.complete(completionStartTime);     return asyncStage.join();   }    private static Future&lt;Duration&gt; startLongTasksInParallelStream(CountDownLatch fjpExhausted) {     ThreadFactory tf = Executors.defaultThreadFactory();     ThreadFactory dtf = runnable -&gt; {       Thread thread = tf.newThread(runnable);       thread.setDaemon(true);       return thread;     };     ExecutorService service = Executors.newSingleThreadExecutor(dtf);     Future&lt;Duration&gt; res = service.submit(() -&gt; {       long startTime = System.nanoTime();       IntStream.range(0, 100).parallel().forEach(num -&gt; {         if (Thread.currentThread() instanceof ForkJoinWorkerThread) {           fjpExhausted.countDown();         }         expensiveProcess(num);       });       return Duration.ofNanos(System.nanoTime() - startTime);     });     service.shutdown();     return res;   }    private static void<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-467719","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467719","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=467719"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467719\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}