Skip to content

Instantly share code, notes, and snippets.

@rea9r
Last active April 7, 2024 14:22
Show Gist options
  • Save rea9r/4984b2a23f9d91d522dc0cd778a899a0 to your computer and use it in GitHub Desktop.
Save rea9r/4984b2a23f9d91d522dc0cd778a899a0 to your computer and use it in GitHub Desktop.
CpuLoadDemo.java
package org.example;
public class CpuLoadDemo {
public static void main(String[] args) {
int processors = Runtime.getRuntime().availableProcessors();
System.out.println("Available processors: " + processors);
for (int i = 0; i < processors; i++) {
new Thread(() -> {
while (true) {
heavyTask();
}
}, "HeavyTaskThread").start();
new Thread(() -> {
while (true) {
lightTask();
}
}, "LightTaskThread").start();
}
}
private static void heavyTask() {
double value = 0;
for (int i = 0; i < Integer.MAX_VALUE; i++) {
value += Math.sin(i) * Math.cos(i);
}
System.out.println("Heavy Task Done: " + value);
}
private static void lightTask() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
System.out.println("Light Task Done");
}
}
@rea9r
Copy link
Author

rea9r commented Apr 7, 2024

取得した Thread Dump

39303:
2024-04-07 21:51:22
Full thread dump OpenJDK 64-Bit Server VM (11.0.19+7-LTS mixed mode):

Threads class SMR info:
_java_thread_list=0x0000600000eb4080, length=30, elements={
0x0000000142167800, 0x000000014216c800, 0x0000000141880800, 0x0000000142168800,
0x0000000142169000, 0x000000014216d800, 0x000000014216e000, 0x000000014187f000,
0x000000014280c800, 0x0000000141944000, 0x0000000141945000, 0x000000014281b000,
0x000000014300f800, 0x0000000143014000, 0x0000000143015000, 0x0000000143015800,
0x000000012f00f800, 0x000000014196a800, 0x000000012f012800, 0x000000012f013800,
0x000000012f014800, 0x000000012f015800, 0x000000012f016000, 0x000000014380f000,
0x00000001439aa800, 0x000000014600a800, 0x000000014600b800, 0x000000014600c000,
0x0000000140809800, 0x0000000146808800
}

"Reference Handler" #2 daemon prio=10 os_prio=31 cpu=0.07ms elapsed=25.40s tid=0x0000000142167800 nid=0x4303 waiting on condition  [0x0000000170d7a000]
   java.lang.Thread.State: RUNNABLE
	at java.lang.ref.Reference.waitForReferencePendingList(java.base@11.0.19/Native Method)
	at java.lang.ref.Reference.processPendingReferences(java.base@11.0.19/Reference.java:241)
	at java.lang.ref.Reference$ReferenceHandler.run(java.base@11.0.19/Reference.java:213)

"Finalizer" #3 daemon prio=8 os_prio=31 cpu=0.10ms elapsed=25.40s tid=0x000000014216c800 nid=0x5103 in Object.wait()  [0x0000000170f86000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(java.base@11.0.19/Native Method)
	- waiting on <0x00000005dfe09008> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base@11.0.19/ReferenceQueue.java:155)
	- waiting to re-lock in wait() <0x00000005dfe09008> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base@11.0.19/ReferenceQueue.java:176)
	at java.lang.ref.Finalizer$FinalizerThread.run(java.base@11.0.19/Finalizer.java:170)

"Signal Dispatcher" #4 daemon prio=9 os_prio=31 cpu=0.32ms elapsed=25.39s tid=0x0000000141880800 nid=0x7f03 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Service Thread" #5 daemon prio=9 os_prio=31 cpu=0.02ms elapsed=25.39s tid=0x0000000142168800 nid=0x7c03 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #6 daemon prio=9 os_prio=31 cpu=6.93ms elapsed=25.39s tid=0x0000000142169000 nid=0x7b03 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task

"C1 CompilerThread0" #9 daemon prio=9 os_prio=31 cpu=31.50ms elapsed=25.39s tid=0x000000014216d800 nid=0x7903 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task

"Sweeper thread" #10 daemon prio=9 os_prio=31 cpu=0.05ms elapsed=25.39s tid=0x000000014216e000 nid=0x5a03 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Common-Cleaner" #11 daemon prio=8 os_prio=31 cpu=0.06ms elapsed=25.37s tid=0x000000014187f000 nid=0x7503 in Object.wait()  [0x0000000171ef2000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	at java.lang.Object.wait(java.base@11.0.19/Native Method)
	- waiting on <0x00000005dff89948> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base@11.0.19/ReferenceQueue.java:155)
	- waiting to re-lock in wait() <0x00000005dff89948> (a java.lang.ref.ReferenceQueue$Lock)
	at jdk.internal.ref.CleanerImpl.run(java.base@11.0.19/CleanerImpl.java:148)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)
	at jdk.internal.misc.InnocuousThread.run(java.base@11.0.19/InnocuousThread.java:161)

"HeavyTaskThread" #12 prio=5 os_prio=31 cpu=22212.62ms elapsed=25.35s tid=0x000000014280c800 nid=0x5e03 runnable  [0x00000001720fe000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #13 prio=5 os_prio=31 cpu=1.59ms elapsed=25.35s tid=0x0000000141944000 nid=0x6103 waiting on condition  [0x000000017230a000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #14 prio=5 os_prio=31 cpu=22674.90ms elapsed=25.35s tid=0x0000000141945000 nid=0x6203 runnable  [0x0000000172516000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #15 prio=5 os_prio=31 cpu=1.99ms elapsed=25.35s tid=0x000000014281b000 nid=0x6503 waiting on condition  [0x0000000172722000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #16 prio=5 os_prio=31 cpu=22632.54ms elapsed=25.35s tid=0x000000014300f800 nid=0x7003 runnable  [0x000000017292e000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #17 prio=5 os_prio=31 cpu=2.47ms elapsed=25.35s tid=0x0000000143014000 nid=0x6e03 waiting on condition  [0x0000000172b3a000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #18 prio=5 os_prio=31 cpu=22494.33ms elapsed=25.35s tid=0x0000000143015000 nid=0x6b03 runnable  [0x0000000172d46000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #19 prio=5 os_prio=31 cpu=2.44ms elapsed=25.35s tid=0x0000000143015800 nid=0x6903 waiting on condition  [0x0000000172f52000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #20 prio=5 os_prio=31 cpu=22336.29ms elapsed=25.35s tid=0x000000012f00f800 nid=0xa803 runnable  [0x000000017315e000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #21 prio=5 os_prio=31 cpu=3.08ms elapsed=25.35s tid=0x000000014196a800 nid=0x8203 waiting on condition  [0x000000017336a000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #22 prio=5 os_prio=31 cpu=22393.25ms elapsed=25.35s tid=0x000000012f012800 nid=0xa503 runnable  [0x0000000173576000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #23 prio=5 os_prio=31 cpu=2.30ms elapsed=25.35s tid=0x000000012f013800 nid=0x8503 waiting on condition  [0x0000000173782000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #24 prio=5 os_prio=31 cpu=22227.33ms elapsed=25.35s tid=0x000000012f014800 nid=0x8703 runnable  [0x000000017398e000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #25 prio=5 os_prio=31 cpu=2.02ms elapsed=25.35s tid=0x000000012f015800 nid=0xa103 waiting on condition  [0x0000000173b9a000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #26 prio=5 os_prio=31 cpu=22541.17ms elapsed=25.35s tid=0x000000012f016000 nid=0x8a03 runnable  [0x0000000173da6000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #27 prio=5 os_prio=31 cpu=1.89ms elapsed=25.35s tid=0x000000014380f000 nid=0x9e03 waiting on condition  [0x0000000173fb2000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #28 prio=5 os_prio=31 cpu=22243.88ms elapsed=25.35s tid=0x00000001439aa800 nid=0x9c03 runnable  [0x00000001741be000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #29 prio=5 os_prio=31 cpu=3.04ms elapsed=25.35s tid=0x000000014600a800 nid=0x9903 waiting on condition  [0x00000001743ca000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"HeavyTaskThread" #30 prio=5 os_prio=31 cpu=22395.90ms elapsed=25.35s tid=0x000000014600b800 nid=0x9803 runnable  [0x00000001745d6000]
   java.lang.Thread.State: RUNNABLE
	at org.example.CpuLoadDemo.heavyTask(CpuLoadDemo.java:26)
	at org.example.CpuLoadDemo.lambda$main$0(CpuLoadDemo.java:11)
	at org.example.CpuLoadDemo$$Lambda$1/0x0000000800065840.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"LightTaskThread" #31 prio=5 os_prio=31 cpu=3.04ms elapsed=25.35s tid=0x000000014600c000 nid=0x9503 waiting on condition  [0x00000001747e2000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(java.base@11.0.19/Native Method)
	at org.example.CpuLoadDemo.lightTask(CpuLoadDemo.java:34)
	at org.example.CpuLoadDemo.lambda$main$1(CpuLoadDemo.java:17)
	at org.example.CpuLoadDemo$$Lambda$2/0x0000000800066c40.run(Unknown Source)
	at java.lang.Thread.run(java.base@11.0.19/Thread.java:829)

"DestroyJavaVM" #32 prio=5 os_prio=31 cpu=51.55ms elapsed=25.34s tid=0x0000000140809800 nid=0x2903 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Attach Listener" #33 daemon prio=9 os_prio=31 cpu=0.90ms elapsed=0.10s tid=0x0000000146808800 nid=0x9303 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"VM Thread" os_prio=31 cpu=4.55ms elapsed=25.40s tid=0x0000000141873800 nid=0x5403 runnable  

"GC Thread#0" os_prio=31 cpu=0.86ms elapsed=25.41s tid=0x0000000141818800 nid=0x3c03 runnable  

"G1 Main Marker" os_prio=31 cpu=0.07ms elapsed=25.41s tid=0x000000014203a000 nid=0x2f03 runnable  

"G1 Conc#0" os_prio=31 cpu=0.02ms elapsed=25.41s tid=0x000000014203b000 nid=0x3803 runnable  

"G1 Refine#0" os_prio=31 cpu=0.07ms elapsed=25.40s tid=0x000000014215f800 nid=0x3703 runnable  

"G1 Young RemSet Sampling" os_prio=31 cpu=1.68ms elapsed=25.40s tid=0x0000000141819800 nid=0x3303 runnable  
"VM Periodic Task Thread" os_prio=31 cpu=8.67ms elapsed=25.38s tid=0x000000014187e000 nid=0x5c03 waiting on condition  

JNI global refs: 6, weak refs: 0


@rea9r
Copy link
Author

rea9r commented Apr 7, 2024

スクリーンショット 2024-04-07 22 56 29

@rea9r
Copy link
Author

rea9r commented Apr 7, 2024

スクリーンショット 2024-04-07 23 22 38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment