通过继承Thread类的方式创建线程

package com.twod4z;
/**
 * @program: com.twod4z
 * @description:
 * @author: Mr.Lin
 * @create: 2019年8月7日
 **/
public class MyThread extends Thread{    
    public void run() {               
        for(int i=0;i<=20;i++) {                             
            Thread t=Thread.currentThread();                                            
            System.out.println((i+1)+".你好,来自线程"+t.getName());                  
        }              
    }
}
MyThtread
package com.twod4z;
/**
 * @program: com.twod4z
 * @description:
 * @author: Mr.Lin
 * @create: 2019年8月7日
 **/
public class Test {
    public static void main(String[] args) {
        MyThread myThread1 = new MyThread();               
        MyThread myThread2 = new MyThread();                                
        myThread1.start();                 
        myThread2.start();
    }
}
Test

原文地址:https://www.cnblogs.com/lpbk/p/11316659.html