public class ex3 {
public static void main(String [] args) {
thread2 t1 = new thread2("hello"); t1.start();
try {
t1.join();
//Thread.sleep(0);
} catch(InterruptedException e) {} for(int i=1;i<=200;i++){
System.out.println("nihao");
}
}
} class thread2 extends Thread {
thread2(String a) {
super(a);
} public void run(){
for(int i =1;i<=200;i++) {
System.out.println("shijie"+getName());
try {
sleep(1000);
} catch(InterruptedException e) {
return;
}
}
}
}
今天看了下join方法,理解呢,应该是加的那条线程执行完之后再执行主线程,今天试了下继承来写多线程,试了老半天都不行,也不知道怎么回事。。。(/ □ \)