File tree Expand file tree Collapse file tree
tool-java-hotcode/src/main/java/com/wdbyte/hotcode Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ public class HotCode {
2020
2121 public static void main (String [] args ) {
2222 // 模拟 CPU 过高
23- // cpuHigh();
23+ cpuHigh ();
2424 // 模拟线程阻塞,线程池容量为1,塞入两个线程,会有一个一直等待
2525 thread ();
2626 // 模拟线程死锁
@@ -92,11 +92,14 @@ public static void addHashSetThread() {
9292 */
9393 private static void cpuHigh () {
9494 Thread thread = new Thread (() -> {
95- double pi = 0 ;
96- for (int i = 0 ; i < Integer .MAX_VALUE ; i ++) {
97- pi += Math .pow (-1 , i ) / (2 * i + 1 );
95+ Thread .currentThread ().setName ("cpu_high_thread" );
96+ while (true ){
97+ double pi = 0 ;
98+ for (int i = 0 ; i < Integer .MAX_VALUE ; i ++) {
99+ pi += Math .pow (-1 , i ) / (2 * i + 1 );
100+ }
101+ System .out .println ("Pi: " + pi * 4 );
98102 }
99- System .out .println ("Pi: " + pi * 4 );
100103 });
101104 thread .start ();
102105 }
You can’t perform that action at this time.
0 commit comments