方法一: 继承Thread
import java.io.IOException;
/**
* 方法一: 继承Thread
*/
public class M01ExtentThread {
public static void main(String[] args) throws IOException {
M01ExtentThread test = new M01ExtentThread();
MyThread thread1 = test.new MyThread();
MyThread thread2 = test.new MyThread();
thread1.setName("线程1");
thread2.setName("线程2");
thread1.start();
thread2.start();
System.out.println("主线程输出");
}
class MyThread extends Thread{
@Override
public void run() {
for(int i = 0; i < 3; i++) {
System.out.println(Thread.currentThread().getName()+"线程输出"+i);
}
}
}
}