【java调式】dump出来的不应该是只有1个线程吗?为什么有好几个?

我用jstack打印了一个基本的只有main方法里面写了一个循环的程序,但是产看dump的文件,发现不止一个Thread
请问其他的都是什么,或者有资料给我一份参考谢谢

 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.161-b12 mixed mode):

"Attach Listener" #9 daemon prio=9 os_prio=0 tid=0x00007f052c001000 nid=0x2a92 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Service Thread" #8 daemon prio=9 os_prio=0 tid=0x00007f05680da800 nid=0x2a5d runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread2" #7 daemon prio=9 os_prio=0 tid=0x00007f05680bd000 nid=0x2a5c waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f05680bb000 nid=0x2a5b waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f05680b8800 nid=0x2a5a waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f05680b6800 nid=0x2a59 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f0568083800 nid=0x2a58 in Object.wait() [0x00007f0552d14000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x000000076dd88ec0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
    - locked <0x000000076dd88ec0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f056807f000 nid=0x2a57 in Object.wait() [0x00007f0552e15000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x000000076dd86b68> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:502)
    at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
    - locked <0x000000076dd86b68> (a java.lang.ref.Reference$Lock)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)

"main" #1 prio=5 os_prio=0 tid=0x00007f0568009000 nid=0x2a51 runnable [0x00007f056ffc7000]
   java.lang.Thread.State: RUNNABLE
    at While.add(While.java:13)
    at While.main(While.java:7)

"VM Thread" os_prio=0 tid=0x00007f0568077800 nid=0x2a56 runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f056801e800 nid=0x2a52 runnable 

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f0568020000 nid=0x2a53 runnable 

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f0568022000 nid=0x2a54 runnable 

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f0568024000 nid=0x2a55 runnable 

"VM Periodic Task Thread" os_prio=0 tid=0x00007f05680df800 nid=0x2a5e waiting on condition 

JNI global references: 9

3个回答

这里的main的线程确实是只有一个,但是其他的有JVM线程,以及其他的C线程....也包括你的系统运行的线程,主线程只有一个,其他的辅助的也有很多。

这里面显示的是Java虚拟机里面所有的线程,这里面包括GC线程等等。并不是你认为的只有一个main线程。

并发编程网一遍文章整理的很好,包括很多常见线程以及描述
http://ifeve.com/jvm-thread/

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!