How is default new thread name given in java?

前端 未结 4 1734
无人及你
无人及你 2020-12-11 03:55

When I run this program

public class Fabric extends Thread {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Fabric());
              


        
4条回答
  •  温柔的废话
    2020-12-11 04:34

    new Thread(new Fabric());
    

    Since Fabric is a Thread, you created 2 threads here :)

    JDK8 code:

    /* For autonumbering anonymous threads. */
    private static int threadInitNumber;
    private static synchronized int nextThreadNum() {
        return threadInitNumber++;
    }
    

提交回复
热议问题