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

后端 未结 3 1566
故里飘歌
故里飘歌 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:23

    public static void main(String[] args) {
        System.out.println(Thread.activeCount());
    
        //doSomething()
    }
    

    The code above output 2

    GC occupies a thread, so you get 2, instead of 1

    This function is designed for debugging

    If you run on debug mode, you would get 1

提交回复
热议问题