提高程序運行速率的!
public class TestThread1{
public static void main(String[] args){
Runner1 r=new Runner1();
//r.run();//這是方法調用,而不是開啟壹個線程
Thread t=new Thread(r);//調用了Thread(Runnable target)方法。且父類對象變量指向子類對象。
t.start();
for(int i=0;i<100;i++){
System.out.println("進入Main Thread運行狀態");
System.out.println(i);
}
}
}
class Runner1 implements Runnable{ //實現了這個接口,jdk就知道這個類是壹個線程
public void run(){
for(int i=0;i<100;i++){
System.out.println("進入Runner1運行狀態");
System.out.println(i);
}
}
}