package com.oldratlee.fucking.concurrency.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ding.lid
 */
public class Utils {
    static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
    static final int THREAD_COUNT = CPU_COUNT * 2;
    static final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
    static volatile boolean isLoadMade = false;

    @SuppressWarnings("InfiniteLoopStatement")
    public static synchronized void makeLoad() {
        if (isLoadMade) return;

        for (int i = 0; i < THREAD_COUNT; ++i) {
            executorService.submit((Runnable) () -> {
                for (int i1 = 1; ; ++i1) {
                    if (i1 % 1000000 == 0) {
                        sleep(1);
                    }
                }
            });
        }
    }

    public static void sleep(long l) {
        try {
            Thread.sleep(l);
        } catch (InterruptedException ignored) {
        }
    }
}

@@ -146,16 +146,46 @@
 hor 
-ding.lid
+Jerry Lee (oldratlee at gmail dot com)
 %0A */
@@ -206,24 +206,32 @@
 Utils %7B%0A    
+private 
 static final
@@ -291,24 +291,32 @@
 sors();%0A    
+private 
 static final
@@ -350,20 +350,29 @@
 NT * 2;%0A
+%0A
     
+private 
 static f
@@ -454,20 +454,29 @@
 COUNT);%0A
+%0A
     
+private 
 static v
@@ -516,55 +516,8 @@
 e;%0A%0A
-    @SuppressWarnings(%22InfiniteLoopStatement%22)%0A
     
@@ -569,20 +569,16 @@
         
-if (
 isLoadMa
@@ -583,16 +583,15 @@
 Made
-) return
+ = true
 ;%0A%0A 
@@ -610,16 +610,32 @@
 int 
-i = 0; i
+taskCount = 0; taskCount
  %3C T
@@ -649,17 +649,25 @@
 OUNT; ++
-i
+taskCount
 ) %7B%0A    
@@ -701,19 +701,8 @@
 mit(
-(Runnable) 
 () -
@@ -731,17 +731,16 @@
 r (int i
-1
  = 1; ; 
@@ -742,17 +742,16 @@
 1; ; ++i
-1
 ) %7B%0A    
@@ -775,16 +775,17 @@
 f (i
-1
  %25 1
+_
 000
+_
 000 
@@ -788,24 +788,73 @@
 000 == 0) %7B%0A
+                        if (!isLoadMade) return;%0A
             
@@ -948,16 +948,87 @@
 %0A    %7D%0A%0A
+    public static void stopLoad() %7B%0A        isLoadMade = false;%0A    %7D%0A%0A
     publ
@@ -1053,17 +1053,22 @@
 ep(long 
-l
+millis
 ) %7B%0A    
@@ -1102,17 +1102,22 @@
 d.sleep(
-l
+millis
 );%0A     

refactor LoadMaker