Skip to content

Commit 6ccf78a

Browse files
committed
feat: opt hotcode
1 parent 17af0f4 commit 6ccf78a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • tool-java-hotcode/src/main/java/com/wdbyte/hotcode

tool-java-hotcode/src/main/java/com/wdbyte/hotcode/HotCode.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)