开发者

Default Threads in Java

How many default Threads are started when ever we call jvm if there is no user crea开发者_如何学JAVAted threads in the code ? I already Know 2 threads are going to start, those are

1) Main thread (Non Daemon Thread)

2) Garbage Collector (Daemon Thread)


The answer depends on your JVM. On mine, a no-op Java program results in the following threads:

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 

You can see for yourself with jstack -l <pid>.


If you have the JDK installed you can use jvisualvm or jconsole (older versions of Java) located in the bin (Windows) directory.

The tool will allow you to see all the threads and their details.

Screenshot attached.

Default Threads in Java

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜