Why the first Thread.activeCount() return 1 but another return 2 in my code?

后端 未结 3 1540
故里飘歌
故里飘歌 2021-01-28 06:34

Here is my application:

public class NamedThread extends Thread {
    /* This will store name of the thread */

    String name;

    @Override
    public void r         


        
3条回答
  •  无人共我
    2021-01-28 07:16

    If we print all the threads then we can observe that default thread group is System and inside the system, there are different threads and groups like :

    Group[system:class java.lang.ThreadGroup]
     Reference
      Finalizer
      Signal Dispatcher
      Group[main:class java.lang.ThreadGroup]
         main
         Monitor
      Group[InnocuousThreadGroup:class java.lang.ThreadGroup]
        Common-Cleaner
    

    In java code default thread group is main. When we print active thread count then it will give an answer as 2 because the main thread group has two threads main and monitor.

提交回复
热议问题