gpt4 book ai didi

java - Java 中的默认线程

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:01:35 28 4
gpt4 key购买 nike

如果代码中没有用户创建的线程,当我们调用 jvm 时会启动多少个默认线程?我已经知道 2 个线程将要启动,它们是

1)主线程(Non Daemon Thread)

2) 垃圾收集器(守护线程)

最佳答案

答案取决于您的 JVM。在我的平台上,一个空操作 Java 程序会产生以下线程:

2011-04-11 10:25:44
Full thread dump Java HotSpot(TM) 64-Bit Server VM (19.1-b02 mixed mode):

"Attach Listener" daemon prio=10 tid=0x0000000040222000 nid=0x606a waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"Low Memory Detector" daemon prio=10 tid=0x0000000040211000 nid=0x6046 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"CompilerThread1" daemon prio=10 tid=0x00007f80d0004000 nid=0x6045 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"CompilerThread0" daemon prio=10 tid=0x00007f80d0001000 nid=0x6044 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"Signal Dispatcher" daemon prio=10 tid=0x000000004020d800 nid=0x6043 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"Finalizer" daemon prio=10 tid=0x00000000401eb000 nid=0x6042 in Object.wait() [0x00007f80d6053000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000eb561300> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118)
- locked <0x00000000eb561300> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

Locked ownable synchronizers:
- None

"Reference Handler" daemon prio=10 tid=0x00000000401e9000 nid=0x6041 in Object.wait() [0x00007f80d6154000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000eb5611d8> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:485)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
- locked <0x00000000eb5611d8> (a java.lang.ref.Reference$Lock)

Locked ownable synchronizers:
- None

"main" prio=10 tid=0x0000000040184800 nid=0x603b runnable [0x00007f80db081000]
java.lang.Thread.State: RUNNABLE
at c.main(c.java:1)

Locked ownable synchronizers:
- None

"VM Thread" prio=10 tid=0x00000000401e2000 nid=0x6040 runnable

"GC task thread#0 (ParallelGC)" prio=10 tid=0x0000000040197800 nid=0x603c runnable

"GC task thread#1 (ParallelGC)" prio=10 tid=0x0000000040199800 nid=0x603d runnable

"GC task thread#2 (ParallelGC)" prio=10 tid=0x000000004019b800 nid=0x603e runnable

"GC task thread#3 (ParallelGC)" prio=10 tid=0x000000004019d000 nid=0x603f runnable

"VM Periodic Task Thread" prio=10 tid=0x000000004021c000 nid=0x6047 waiting on condition

您可以使用 jstack -l <pid> 亲自查看.

关于java - Java 中的默认线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5619223/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com