---
title: "练手java thread(三)"
author: "junlas"
date: "2010-12-19T00:58:42Z"
tags: []
categories: ["编程语言"]
slug: "java-thread"
draft: false
lastmod: "2010-12-19T00:58:42Z"
id: 846443
url: "https://junlas.iteye.com/blog/846443"
---

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