ITeye博客

练手java thread(三)

junlas · 2010-12-19 00:58 · java · 编程语言 · Markdown

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());
		}
	}
	
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。