{"id":284824,"date":"2017-04-11T22:50:35","date_gmt":"2017-04-11T18:50:35","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284824"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284824","title":{"rendered":"\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043c\u0438\u0440\u0435 java. \u041f\u0443\u043b \u043f\u043e\u0442\u043e\u043a\u043e\u0432"},"content":{"rendered":"<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u043b\u0430\u0441\u0438\u0442: \u043d\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class Counter {      public Double count(double a) {         for (int i = 0; i &lt; 1000000; i++) {             a = a + Math.tan(a);         }          return a;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0440\u044f\u0434 \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c*:<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"java\">public class SingleThreadClient {      public static void main(String[] args) {         Counter counter = new Counter();          long start = System.nanoTime();          double value = 0;         for (int i = 0; i &lt; 400; i++) {             value += counter.count(i);         }          System.out.println(format(&quot;Executed by %d s, value : %f&quot;,                 (System.nanoTime() - start) \/ (1000_000_000),                 value));     } }<\/code><\/pre>\n<p>  \u041d\u0430 \u043c\u043e\u0435\u0439 \u0442\u0430\u0447\u043a\u0435 \u0441 4 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044f\u0434\u0440\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<br \/>  <em>top -pid {pid}<\/em>:  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*OLiGfzSctLZecfh90DHgaQ.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f 104 \u0441\u0435\u043a.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u043d\u0430 \u043e\u0434\u0438\u043d java-\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441 \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 100%, \u043d\u043e \u043e\u0431\u0449\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 2,5%, \u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class MultithreadClient {      public static void main(String[] args) throws ExecutionException, InterruptedException {         ExecutorService threadPool = Executors.newFixedThreadPool(8);         Counter counter = new Counter();          long start = System.nanoTime();          List&lt;Future&lt;Double&gt;&gt; futures = new ArrayList&lt;&gt;();         for (int i = 0; i &lt; 400; i++) {             final int j = i;             futures.add(                     CompletableFuture.supplyAsync(                             () -&gt; counter.count(j),                             threadPool                     ));         }          double value = 0;         for (Future&lt;Double&gt; future : futures) {             value += future.get();         }          System.out.println(format(&quot;Executed by %d s, value : %f&quot;,                 (System.nanoTime() - start) \/ (1000_000_000),                 value));          threadPool.shutdown();     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u043d\u044f\u0442\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*hkvBnDB1q4Z6we_gjrfCDg.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<h3 id=\"threadpoolexecutor\">ThreadPoolExecutor<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 ThreadPool \u2014 \u0432 java \u0435\u0433\u043e \u0440\u043e\u043b\u044c \u0438\u0433\u0440\u0430\u0435\u0442 ThreadPoolExecutor, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u043b\u0438 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Utilities. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u044c ThreadPoolExecutor, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">private final BlockingQueue&lt;Runnable&gt; workQueue;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0447\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0443\u043b\u0430. \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043f\u0443\u043b\u0430, \u043f\u0443\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public void execute(Runnable command) {    ...     if (workerCountOf(c) &lt; corePoolSize) {         if (addWorker(command, true))             return;    ...    if (isRunning(c) &amp;&amp; workQueue.offer(command)) {    ...        addWorker(null, false);    ...     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 addWorker \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 Runnable, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 workQueue \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0438\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">final void runWorker(Worker w) {    ...     try {         while (task != null || (task = workQueue.poll(keepAliveTime, TimeUnit.NANOSECONDS)) != null) {            ...                  task.run();    ... }<\/code><\/pre>\n<p>  <\/p>\n<p>ThreadPoolExecutor \u0438\u043c\u0435\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 javadoc, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0444\u0440\u0430\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class ThreadPool implements Executor {     private final static Queue&lt;Runnable&gt; workQueue = new ConcurrentLinkedQueue&lt;&gt;();     private static volatile boolean isRunning = true;      public ThreadPool(int nThreads) {         for (int i = 0; i &lt; nThreads; i++) {             new Thread(new TaskWorker()).start();         }     }      @Override     public void execute(Runnable command) {         if (isRunning) {             workQueue.offer(command);         }     }      public void shutdown() {         isRunning = false;     }      private final class TaskWorker implements Runnable {          @Override         public void run() {             while (isRunning) {                 Runnable nextTask = workQueue.poll();                 if (nextTask != null) {                     nextTask.run();                 }             }         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0443 \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0443, \u0447\u0442\u043e \u0438 \u0432\u044b\u0448\u0435, \u0441 \u043d\u0430\u0448\u0438\u043c \u043f\u0443\u043b\u043e\u043c.<br \/>  \u041c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 MultithreadClient:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">\/\/ ExecutorService threadPool = Executors.newFixedThreadPool (8); ThreadPool threadPool = \u043d\u043e\u0432\u044b\u0439 ThreadPool (8);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u2014 15 \u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<p>  <\/p>\n<h3 id=\"razmer-pula-potokov\">\u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u0443\u043b\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u043f\u0443\u043b\u0435 \u2014 \u0434\u043e 100.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">ThreadPool threadPool = new ThreadPool(100);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u043b\u043e\u0441\u044c \u0434\u043e 28 \u0441\u0435\u043a\u0443\u043d\u0434 \u2014 \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e?<\/p>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0433\u043b\u0430 \u0443\u043f\u0430\u0441\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437-\u0437\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430\u0434 \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041f\u043e\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u200b\u200b\u0437\u0430\u043d\u044f\u0442\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439, \u043e\u043d\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0437\u0430\u0434\u0430\u0447\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043d\u0430 csw \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b top.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 8 \u043f\u043e\u0442\u043e\u043a\u0430\u0445:<br \/>  <img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1000\/1*-OUi0aTP5y6TmUw_8dO08w.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u041d\u0430 100 \u043f\u043e\u0442\u043e\u043a\u0430\u0445:<br \/>  <img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1000\/1*MmqNmLGZnV0uK5ySfCi5iQ.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0443\u043b\u0430?<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0443\u043b\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0440\u0435\u0434\u043a\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0437\u0430\u0445\u0430\u0440\u0434\u043e\u043a\u043e\u0436\u0435\u043d, \u0441\u043a\u043e\u0440\u0435\u0435 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0437 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044f, \u0447\u0442\u043e \u043f\u043e\u0442\u043e\u043a\u0438 \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u043d\u0435\u0442 \u0446\u0438\u043a\u043b\u043e\u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f I\/O, \u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u0434\u0430\u0447 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e, \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439<br \/>  \u043f\u0443\u043b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 = Runtime.getRuntime().availProcessors () + 1.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0442\u043e\u043a\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043e\u0436\u0438\u0434\u0430\u044e\u0442 I\/O, \u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0443\u043b\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d \u043d\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0430\u0442\u0438\u0442 50% \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 iowait, \u0442\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0443\u043b\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c<br \/>  2 * Runtime.getRuntime().availableProcessors () + 1.<\/p>\n<p>  <\/p>\n<h3 id=\"drugie-vidy-pulov\">\u0414\u0440\u0443\u0433\u0438\u0435 \u0432\u0438\u0434\u044b \u043f\u0443\u043b\u043e\u0432<\/h3>\n<p>  <\/p>\n<ol>\n<li>\n<p>\u041f\u0443\u043b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u0447<br \/>  <a href=\"http:\/\/netty.io\/3.5\/api\/org\/jboss\/netty\/handler\/execution\/MemoryAwareThreadPoolExecutor.html\">MemoryAwareThreadPoolExecutor<\/a><\/p>\n<p>  <\/li>\n<li>\u041f\u0443\u043b \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 JMX-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043f\u0443\u043b\u0430 \u0432 runtime.<br \/>  <a href=\"Http:\/\/www.grepcode.com\/file\/repo1.maven.org\/maven2\/org.apache.cassandra\/cassandra-all\/2.0.13\/org\/apache\/cassandra\/concurrent\/JMXEnabledThreadPoolExecutor.java?av=h\">JMXEnabledThreadPoolExecutor<\/a><\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/kuptservol\/how-it-works\/tree\/master\/src\/main\/java\/ru\/skuptsov\/thread\/pool\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>[*] \u2014 \u0442\u0435\u0441\u0442 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u044b\u043c, \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435: <a href=\"http:\/\/openjdk.java.net\/projects\/code-tools\/jmh\/\">http:\/\/openjdk.java.net\/projects\/code-tools\/jmh\/<\/a><\/p>\n<p> \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:\/\/habrahabr.ru\/post\/326146\/\"> https:\/\/habrahabr.ru\/post\/326146\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u043b\u0430\u0441\u0438\u0442: \u043d\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class Counter {      public Double count(double a) {         for (int i = 0; i &lt; 1000000; i++) {             a = a + Math.tan(a);         }          return a;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0440\u044f\u0434 \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c*:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284824","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284824","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=284824"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284824\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}