package unittest;
public class Test extends Thread{
String title;
Test(String title){
this.title = title;
}
public void run(){
for(int i = 0; i < 3; i++){
System.out.println(this.title+ ":hello " + i);
}
}
public static void main(String[] args) {
//直接調用run方法,沒有併發執行,而是順序執行
new Test(“Thread 1”).run();
new Test(“Thread 2”).run();
new Test(“Thread 3”).run();
/*
//調用start方法,併發執行,出現交替執行的現象
new Test("Thread 1").start();
new Test("Thread 2").start();
new Test("Thread 3").start();
*/
throw new RuntimeException("");
}
}