练手java thread(三)
Thread类的join方法测试:
package thread.test03;
public class ThreadJoinTest {
public static void main(String[] args) {
Thread tt = new TestThread();
tt.start();
int index = 0;
while(true){
if(index++ == 100){
try {
tt.join();//join():等待tt线程终止,再接着执行当前线程;join(long millis):指定一定的时间
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("main:"+Thread.currentThread().getName());
}
}
}
class TestThread extends Thread{
@Override
public void run() {
while(true){
System.out.println("run:"+Thread.currentThread().getName());
}
}
}