`
junlas
  • 浏览: 61442 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

练手java thread(三)

    博客分类:
  • java
阅读更多

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());
		}
	}
	
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics