java线程学习之线程的开启

线程开启(and命名):

 // 线程1
    Thread myThread = new Thread("threadNo1"){
        public void run(){
            System.out.println("线程No1");
        }
    };
    //线程2
    MyThread mt = new MyThread();
    //线程3
    Thread threadNo3 = new Thread(){
        public void run(){
            System.out.println("线程No3");
        }
    };

    //Thread threadNo4 = new Thread(Task);
    threadNo3.setName("threadNo3");
    //线程1的开启
    myThread.start();
    //线程2的开启
    mt.start();
    //线程3的开启
    threadNo3.start();

}


public static class MyThread  extends Thread{
    public MyThread() {
        super("threadNo2");
    }
    public void run(){
        System.out.println("线程No2");
    }
}

posted @ 2022-07-17 23:14  搬砖的孟达  阅读(12)  评论(0)    收藏  举报  来源