{"id":330511,"date":"2022-03-10T21:00:56","date_gmt":"2022-03-10T21:00:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=330511"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=330511","title":{"rendered":"<span>Java: \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u0430\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/b60\/149\/be2\/b60149be2c6c5d2cd42f4cd7d23e3387.jpg\" width=\"8124\" height=\"5001\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b60\/149\/be2\/b60149be2c6c5d2cd42f4cd7d23e3387.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c: \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b, \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c API, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u043c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441\u043e \u0441\u043c\u0435\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u044b \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430\u043c\u0438 \u0432 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0442\u0440\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c.<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f-\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f <\/h2>\n<p>\u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0433\u0434\u0435 \u0434\u0432\u0435 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0431\u0449\u0438\u0439 \u0431\u0443\u0444\u0435\u0440. \u041e\u0434\u043d\u0430 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0433\u0440\u0443\u043f\u043f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ab\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0438\u00bb, \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0437\u0430\u043a\u0438\u0434\u044b\u0432\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0443\u0444\u0435\u0440, \u0430 \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ab\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438\u00bb, \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u0442\u044f\u0433\u0438\u0432\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u2013 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0442\u044f\u043d\u0443\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u043e\u043a\u0438 \u043d\u0435 \u043e\u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0432\u0435\u0434\u0435\u043d\u0430 \u0434\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c, \u043d\u043e \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430<\/h2>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0441 \u0444\u0430\u043a\u0443\u043b\u044c\u0442\u0435\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u043a\u0438. \u041e\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u0434\u0430\u043b \u044d\u043a\u0437\u0430\u043c\u0435\u043d \u043f\u043e \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0443 \u201c<a href=\"https:\/\/www.piter.com\/collection\/all\/product\/java-concurrency-na-praktike\">\u0412\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u0443\u0440\u0441 \u043f\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 Java<\/a>\u201d \u0438 \u043a\u043e\u0435-\u0447\u0442\u043e \u0437\u043d\u0430\u0435\u0442 \u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c \u0441\u043b\u043e\u0432\u0435 \u00a0<code>synchronized<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f. \u041e\u043d \u043d\u0430\u043c\u0435\u0440\u0435\u043d \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0447\u0442\u043e \u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a? \u0421\u0442\u0443\u0434\u0435\u043d\u0442\u0443 \u043c\u043d\u043e\u0433\u043e \u043d\u0435 \u043d\u0430\u0434\u043e, \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 <code>List<\/code>\u00a0\u043f\u043b\u044e\u0441 \u0434\u0432\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430 \u2013 \u0432\u043e\u0442 \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e:<\/p>\n<pre><code class=\"java\">package concurency;  import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.stream.Collectors; import java.util.stream.IntStream;  public class Student {     List&lt;integer> buffer = new LinkedList&lt;>();      private Runnable producer = () -> {         Random r = new Random();         while (true) {             try {                 int item = r.nextInt();                 System.out.println(\"Produced: \" + item);                 produce(item);                 Thread.sleep(1000 + r.nextInt(1000));             } catch (InterruptedException e) {                 e.printStackTrace();             }         }      };      private Runnable consumer = () -> {         while(true) {             try {                 Integer consumed = consume();                 System.out.println(\"Consumed: \" + consumed);             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     };       private void produce(Integer item) {         synchronized (buffer) {             buffer.add(item);             buffer.notifyAll();         }     }      private Integer consume() throws InterruptedException {         synchronized (buffer) {             while (buffer.isEmpty()) {                 buffer.wait();             }             Integer removed = buffer.remove(0);             buffer.notifyAll();             return removed;         }     }      public void play() {         List&lt;thread> threads = IntStream.range(0, 10).boxed()                 .map(i -> new Thread(producer))                 .collect(Collectors.toList());         IntStream.range(0, 10).boxed()                 .map(i -> new Thread(consumer))                 .forEach(threads::add);         threads.forEach(Thread::start);         threads.forEach(thread -> {             try {                 thread.join();             } catch (InterruptedException e) {                 e.printStackTrace();             }         });     }      public static void main(String[] args) {         new Student().play();     } }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0435\u043d \u0438 \u0431\u0430\u043d\u0430\u043b\u0435\u043d. \u0412\u0441\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0431\u043b\u043e\u043a\u0430 <code>synchronized<\/code>, \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u0431\u0443\u0444\u0435\u0440\u0435 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c. \u041f\u043e\u0442\u043e\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e. \u0414\u0430, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0435\u043d, \u043d\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0449\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0435\u0440\u0430<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043a\u043e\u0434\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u00ab\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u043c-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c \u043d\u0430 Java\u00bb. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u044b\u0442 \u0443 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c, \u043e\u043d \u0441\u043b\u044b\u0448\u0430\u043b \u043e \u043d\u043e\u0432\u044b\u0445 \u043f\u0430\u043a\u0435\u0442\u0430\u0445, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u0432 Java 1.5 (\u0434\u0430-\u0434\u0430!) \u0438 \u0447\u0443\u0432\u0441\u0442\u0432\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0431\u044b \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043b\u0443\u0447\u0448\u0435. \u041f\u0440\u043e\u0441\u043b\u0443\u0448\u0430\u0432 \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u043b\u0435\u043a\u0446\u0438\u044e \u043d\u0430 \u0442\u0435\u043c\u0443 \u00ab\u041a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c Java \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435\u00bb \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0440\u044b\u0432\u0448\u0438\u0441\u044c \u043d\u0430 StackOverflow, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"java\">package concurency;  import java.util.Random; import java.util.concurrent.*;  import java.util.stream.IntStream;  public class Engineer {     BlockingQueue&lt;integer> buffer = new LinkedBlockingQueue&lt;>();      private Runnable producer = () -> {         Random r = new Random();         while (true) {             try {                 int item = r.nextInt();                 System.out.println(\"Produced: \" + item);                 buffer.put(item);                 Thread.sleep(1000 + r.nextInt(1000));             } catch (InterruptedException e) {                 e.printStackTrace();             }         }      };      private Runnable consumer = () -> {         while(true) {             try {                 Integer consumed = buffer.take();                 System.out.println(\"Consumed: \" + consumed);             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     };      public void play() {         ExecutorService executor = Executors.newCachedThreadPool();          IntStream.range(0, 10).boxed()                 .map(i -> producer)                 .forEach(executor::submit);         IntStream.range(0, 10).boxed()                 .map(i -> consumer)                 .forEach(executor::submit);         try {             executor.awaitTermination(Long.MAX_VALUE,TimeUnit.DAYS);         } catch (InterruptedException e) {             e.printStackTrace();         }     }      public static void main(String[] args) {         new Engineer().play();     } }<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041e\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a\u043e\u0440\u043e\u0447\u0435, \u0438 \u0432 \u043d\u0435\u043c \u043d\u0435\u0442 \u0431\u043b\u043e\u043a\u043e\u0432 <code>synchronized<\/code>. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438, \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u2013 \u044d\u0442\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a, \u043c\u043e\u0436\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430 \u2013 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0448\u0430\u0433 \u0432\u043f\u0435\u0440\u0435\u0434. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u041a\u043e\u0434\u0435\u0440 \u0440\u0435\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0440\u0443\u0447\u043d\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0430 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f ExecutorService \u2013 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0432 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0439 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0441 \u0441\u044b\u0440\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0443 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, ExecutorService \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Callable, \u0430 \u043d\u0435 Runnable, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. <\/p>\n<p>\u041d\u043e \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u0443\u0442 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u0430: \u0432 \u043a\u043e\u0434\u0435 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0449\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438. \u0427\u0442\u043e\u0431\u044b \u0441 \u044d\u0442\u0438\u043c \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u0440\u0435\u0442\u044c\u0435, \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0433\u0438\u043a\u0430<\/h2>\n<p>\u0418 \u0432\u043e\u0442 \u0437\u0430 \u0434\u0435\u043b\u043e \u0431\u0435\u0440\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.piter.com\/collection\/A32872\/product\/kak-upravlyat-intellektualami-ya-nerdy-i-giki\">\u0433\u0438\u043a<\/a>. \u0415\u043c\u0443 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0440\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0412\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434: <\/p>\n<pre><code class=\"java\">package concurency;  import java.util.Random; import java.util.concurrent.*; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.IntStream;  public class Geek {     private Random r = new Random();      private Supplier&lt;integer> producer = () -> {         int item = r.nextInt();         System.out.println(\"Produced: \" + item + \" by \" + Thread.currentThread().getName());         return item;     };      private Consumer&lt;integer> consumer = i -> {         System.out.println(\"Consumed: \" + i + \" by \" + Thread.currentThread().getName());     };      public void play() {         while (true) {             IntStream.range(0, 10).boxed().forEach(i ->             CompletableFuture.supplyAsync(producer)                     .thenAcceptAsync(consumer));             try {                 Thread.sleep(500 + r.nextInt(500));             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     }      public static void main(String[] args) {         new Geek().play();     } }<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043a\u043e\u0434 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u043e\u0447\u0435 \u0438 \u043f\u0440\u043e\u0449\u0435 \u2013 \u043d\u043e \u0432 \u043d\u0435\u043c \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u0430\u044f \u0441\u043c\u0435\u043d\u0430 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u044b. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u0442\u044c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c <code>Runnable<\/code>, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b\u00a0<code>Supplier<\/code>\u00a0\u0438\u00a0<code>Consumer<\/code>\u00a0\u2013 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u00a0<code>ExecutionService<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043b\u0433\u043e\u0438\u0433\u0440\u0430\u044e\u0449\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>CompletableFuture<\/code>\u00a0\u0434\u043b\u044f \u043c\u0435\u043b\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u043c\u0430\u0445\u043e\u043c. <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u0431\u0443\u0444\u0435\u0440\u0430 \u2013 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044e \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0442\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439. \u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0432 <strong>\u043d\u0438 \u0435\u0434\u0438\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/strong>.<\/p>\n<p>\u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043b\u0438\u0448\u044c \u0441\u043b\u0435\u0433\u043a\u0430 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435\u00a0<code>CompletableFuture<\/code>. \u0418\u043c\u0435\u044f \u0434\u0435\u043b\u043e \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u044d\u0442\u0430\u043f\u043d\u043e, \u0432\u044b\u0440\u0430\u0436\u0430\u044f \u0442\u0430\u043a\u0438\u0435 \u044d\u0442\u0430\u043f\u044b \u043a\u0430\u043a <code>Function<\/code>,\u00a0<code>Consumer<\/code> \u0438\u043b\u0438\u00a0<code>Runnable<\/code>\u00a0(\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\/\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b). \u042d\u0442\u0430\u043f\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0441\u0446\u0435\u043f\u043b\u044f\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u0443\u044f\u0441\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u0442\u0430\u043f\u043e\u0432 (\u0438\u043b\u0438 \u044d\u0442\u0430\u043f\u0430). \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u044d\u0442\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u2013 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 Java \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f. \u00a0<code>CompletableFuture<\/code>\u00a0\u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u043b\u0438 \u044f\u0437\u044b\u043a \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438; \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438 \u043d\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430\u0445 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0440\u0443\u0447\u043d\u043e\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438. \u041f\u043e\u0442\u043e\u043a\u0438 \u0432 Java \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0437\u044b\u043a\u0430, \u0432\u0441\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e \u043d\u0438\u0445 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u2013 \u043d\u0435\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0431\u0435\u0437 \u043d\u0438\u0445 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0435 \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 &#8212; System.exit(), \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0434\u043a\u043e. \u041f\u0440\u0430\u0432\u0434\u0430, \u044d\u0442\u043e \u0443\u0436\u0435 \u0442\u0435\u043c\u0430 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/company\/piter\/blog\/655069\/\"> https:\/\/habr.com\/ru\/company\/piter\/blog\/655069\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c: \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b, \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c API, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u043c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441\u043e \u0441\u043c\u0435\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u044b \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430\u043c\u0438 \u0432 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0442\u0440\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c.<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f-\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f <\/h2>\n<p>\u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0433\u0434\u0435 \u0434\u0432\u0435 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0431\u0449\u0438\u0439 \u0431\u0443\u0444\u0435\u0440. \u041e\u0434\u043d\u0430 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0433\u0440\u0443\u043f\u043f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ab\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0438\u00bb, \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0437\u0430\u043a\u0438\u0434\u044b\u0432\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0443\u0444\u0435\u0440, \u0430 \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ab\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438\u00bb, \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u0442\u044f\u0433\u0438\u0432\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u2013 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0442\u044f\u043d\u0443\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u043e\u043a\u0438 \u043d\u0435 \u043e\u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0432\u0435\u0434\u0435\u043d\u0430 \u0434\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c, \u043d\u043e \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430<\/h2>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0441 \u0444\u0430\u043a\u0443\u043b\u044c\u0442\u0435\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u043a\u0438. \u041e\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u0434\u0430\u043b \u044d\u043a\u0437\u0430\u043c\u0435\u043d \u043f\u043e \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0443 \u201c<a href=\"https:\/\/www.piter.com\/collection\/all\/product\/java-concurrency-na-praktike\">\u0412\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u0443\u0440\u0441 \u043f\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 Java<\/a>\u201d \u0438 \u043a\u043e\u0435-\u0447\u0442\u043e \u0437\u043d\u0430\u0435\u0442 \u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c \u0441\u043b\u043e\u0432\u0435 \u00a0<code>synchronized<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f. \u041e\u043d \u043d\u0430\u043c\u0435\u0440\u0435\u043d \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0447\u0442\u043e \u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a? \u0421\u0442\u0443\u0434\u0435\u043d\u0442\u0443 \u043c\u043d\u043e\u0433\u043e \u043d\u0435 \u043d\u0430\u0434\u043e, \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 <code>List<\/code>\u00a0\u043f\u043b\u044e\u0441 \u0434\u0432\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430 \u2013 \u0432\u043e\u0442 \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e:<\/p>\n<pre><code class=\"java\">package concurency;  import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.stream.Collectors; import java.util.stream.IntStream;  public class Student {     List&lt;integer> buffer = new LinkedList&lt;>();      private Runnable producer = () -> {         Random r = new Random();         while (true) {             try {                 int item = r.nextInt();                 System.out.println(\"Produced: \" + item);                 produce(item);                 Thread.sleep(1000 + r.nextInt(1000));             } catch (InterruptedException e) {                 e.printStackTrace();             }         }      };      private Runnable consumer = () -> {         while(true) {             try {                 Integer consumed = consume();                 System.out.println(\"Consumed: \" + consumed);             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     };       private void produce(Integer item) {         synchronized (buffer) {             buffer.add(item);             buffer.notifyAll();         }     }      private Integer consume() throws InterruptedException {         synchronized (buffer) {             while (buffer.isEmpty()) {                 buffer.wait();             }             Integer removed = buffer.remove(0);             buffer.notifyAll();             return removed;         }     }      public void play() {         List&lt;thread> threads = IntStream.range(0, 10).boxed()                 .map(i -> new Thread(producer))                 .collect(Collectors.toList());         IntStream.range(0, 10).boxed()                 .map(i -> new Thread(consumer))                 .forEach(threads::add);         threads.forEach(Thread::start);         threads.forEach(thread -> {             try {                 thread.join();             } catch (InterruptedException e) {                 e.printStackTrace();             }         });     }      public static void main(String[] args) {         new Student().play();     } }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0435\u043d \u0438 \u0431\u0430\u043d\u0430\u043b\u0435\u043d. \u0412\u0441\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0431\u043b\u043e\u043a\u0430 <code>synchronized<\/code>, \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u0431\u0443\u0444\u0435\u0440\u0435 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c. \u041f\u043e\u0442\u043e\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e. \u0414\u0430, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0435\u043d, \u043d\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0449\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0435\u0440\u0430<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043a\u043e\u0434\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u00ab\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u043c-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c \u043d\u0430 Java\u00bb. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u044b\u0442 \u0443 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c, \u043e\u043d \u0441\u043b\u044b\u0448\u0430\u043b \u043e \u043d\u043e\u0432\u044b\u0445 \u043f\u0430\u043a\u0435\u0442\u0430\u0445, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u0432 Java 1.5 (\u0434\u0430-\u0434\u0430!) \u0438 \u0447\u0443\u0432\u0441\u0442\u0432\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0431\u044b \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043b\u0443\u0447\u0448\u0435. \u041f\u0440\u043e\u0441\u043b\u0443\u0448\u0430\u0432 \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u043b\u0435\u043a\u0446\u0438\u044e \u043d\u0430 \u0442\u0435\u043c\u0443 \u00ab\u041a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c Java \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435\u00bb \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0440\u044b\u0432\u0448\u0438\u0441\u044c \u043d\u0430 StackOverflow, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"java\">package concurency;  import java.util.Random; import java.util.concurrent.*;  import java.util.stream.IntStream;  public class Engineer {     BlockingQueue&lt;integer> buffer = new LinkedBlockingQueue&lt;>();      private Runnable producer = () -> {         Random r = new Random();         while (true) {             try {                 int item = r.nextInt();                 System.out.println(\"Produced: \" + item);                 buffer.put(item);                 Thread.sleep(1000 + r.nextInt(1000));             } catch (InterruptedException e) {                 e.printStackTrace();             }         }      };      private Runnable consumer = () -> {         while(true) {             try {                 Integer consumed = buffer.take();                 System.out.println(\"Consumed: \" + consumed);             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     };      public void play() {         ExecutorService executor = Executors.newCachedThreadPool();          IntStream.range(0, 10).boxed()                 .map(i -> producer)                 .forEach(executor::submit);         IntStream.range(0, 10).boxed()                 .map(i -> consumer)                 .forEach(executor::submit);         try {             executor.awaitTermination(Long.MAX_VALUE,TimeUnit.DAYS);         } catch (InterruptedException e) {             e.printStackTrace();         }     }      public static void main(String[] args) {         new Engineer().play();     } }<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041e\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a\u043e\u0440\u043e\u0447\u0435, \u0438 \u0432 \u043d\u0435\u043c \u043d\u0435\u0442 \u0431\u043b\u043e\u043a\u043e\u0432 <code>synchronized<\/code>. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438, \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u2013 \u044d\u0442\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a, \u043c\u043e\u0436\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430 \u2013 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0448\u0430\u0433 \u0432\u043f\u0435\u0440\u0435\u0434. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u041a\u043e\u0434\u0435\u0440 \u0440\u0435\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0440\u0443\u0447\u043d\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0430 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f ExecutorService \u2013 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0432 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0439 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0441 \u0441\u044b\u0440\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0443 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, ExecutorService \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Callable, \u0430 \u043d\u0435 Runnable, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. <\/p>\n<p>\u041d\u043e \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u0443\u0442 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u0430: \u0432 \u043a\u043e\u0434\u0435 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0449\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438. \u0427\u0442\u043e\u0431\u044b \u0441 \u044d\u0442\u0438\u043c \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u0440\u0435\u0442\u044c\u0435, \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0433\u0438\u043a\u0430<\/h2>\n<p>\u0418 \u0432\u043e\u0442 \u0437\u0430 \u0434\u0435\u043b\u043e \u0431\u0435\u0440\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.piter.com\/collection\/A32872\/product\/kak-upravlyat-intellektualami-ya-nerdy-i-giki\">\u0433\u0438\u043a<\/a>. \u0415\u043c\u0443 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f \u0441\u0442\u0440\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0412\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434: <\/p>\n<pre><code class=\"java\">package concurency;  import java.util.Random; import java.util.concurrent.*; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.IntStream;  public class Geek {     private Random r = new Random();      private Supplier&lt;integer> producer = () -> {         int item = r.nextInt();         System.out.println(\"Produced: \" + item + \" by \" + Thread.currentThread().getName());         return item;     };      private Consumer&lt;integer> consumer = i -> {         System.out.println(\"Consumed: \" + i + \" by \" + Thread.currentThread().getName());     };      public void play() {         while (true) {             IntStream.range(0, 10).boxed().forEach(i ->             CompletableFuture.supplyAsync(producer)                     .thenAcceptAsync(consumer));             try {                 Thread.sleep(500 + r.nextInt(500));             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     }      public static void main(String[] args) {         new Geek().play();     } }<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043a\u043e\u0434 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u043e\u0447\u0435 \u0438 \u043f\u0440\u043e\u0449\u0435 \u2013 \u043d\u043e \u0432 \u043d\u0435\u043c \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u0430\u044f \u0441\u043c\u0435\u043d\u0430 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u044b. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u0442\u044c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c <code>Runnable<\/code>, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b\u00a0<code>Supplier<\/code>\u00a0\u0438\u00a0<code>Consumer<\/code>\u00a0\u2013 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u00a0<code>ExecutionService<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043b\u0433\u043e\u0438\u0433\u0440\u0430\u044e\u0449\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>CompletableFuture<\/code>\u00a0\u0434\u043b\u044f \u043c\u0435\u043b\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u043c\u0430\u0445\u043e\u043c. <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u0431\u0443\u0444\u0435\u0440\u0430 \u2013 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044e \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0442\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439. \u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0432 <strong>\u043d\u0438 \u0435\u0434\u0438\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/strong>.<\/p>\n<p>\u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043b\u0438\u0448\u044c \u0441\u043b\u0435\u0433\u043a\u0430 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435\u00a0<code>CompletableFuture<\/code>. \u0418\u043c\u0435\u044f \u0434\u0435\u043b\u043e \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u044d\u0442\u0430\u043f\u043d\u043e, \u0432\u044b\u0440\u0430\u0436\u0430\u044f \u0442\u0430\u043a\u0438\u0435 \u044d\u0442\u0430\u043f\u044b \u043a\u0430\u043a <code>Function<\/code>,\u00a0<code>Consumer<\/code> \u0438\u043b\u0438\u00a0<code>Runnable<\/code>\u00a0(\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\/\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b). \u042d\u0442\u0430\u043f\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0441\u0446\u0435\u043f\u043b\u044f\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u0443\u044f\u0441\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u0442\u0430\u043f\u043e\u0432 (\u0438\u043b\u0438 \u044d\u0442\u0430\u043f\u0430). \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u044d\u0442\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u2013 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 Java \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f. \u00a0<code>CompletableFuture<\/code>\u00a0\u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u043b\u0438 \u044f\u0437\u044b\u043a \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438; \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438 \u043d\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e<\/p>\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-330511","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330511","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=330511"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330511\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}