小程序,线程的启动用start方法,开线程的类,可以实现runnable接口,还可以从Thread类继承,继承不是个好办法、
public class MultiThreadModel1 {
public static void main(String args[]){
MyThreadModel m = new MyThreadModel("First");
m.start();
MyThreadModel m2 = new MyThreadModel("Second");
m2.start();
MyThreadModel m3 = new MyThreadModel("Third");
m3.start();
System.out.println("主线程启动");
for(int i=0;i<=100;i++){
System.out.print("-------->");
}
System.out.print("主线程结束");
}
}
class MyThreadModel extends Thread{
MyThreadModel(String name){
this.name = name;
}
public void run(){
for(int i =0; i< 100; i++){
System.out.print(name+" ");
}
}
private String name ;
}
Tags -
java ,
线程