这种方式是以实现接口为主,第一种方式是继承类为主。
public class ThreadTest02 {
public static void main(String[] args) {
//创建一个可运行的对象
MyRunnable r = new MyRunnable();
//将可运行的对象封装成一个线程对象
Thread t = new Thread(r);
//启动线程
t.start();
for(int i =0;i<1000;i++){
System.out.println("主线程---->"+i);
}
}
}
class MyRunnable implements Runnable{
public void run(){
for(int i = 0;i<1000;i++){
System.out.println("分线程---->"+i);
}
}
}



