---
title: "线程学习之join()"
author: "arne3166"
date: "2010-10-14T11:44:44Z"
tags: []
categories: ["编程语言"]
slug: "join"
draft: false
lastmod: "2010-10-14T11:44:44Z"
id: 784656
url: "https://arne3166.iteye.com/blog/784656"
---

```
class HelloThread extends Thread {
	String message;
	
	HelloThread( String message ) {
		this.message = message;
	}
	
	public void run() {
		int sleeptime = ( int )( Math.random() * 3000 );
		try {
			sleep( sleeptime );
		}catch( InterruptedException e) {}
		System.out.println(message);
	}
	
	public static void main(String[] args) throws InterruptedException {
		HelloThread ht1 = new HelloThread( "good " );
		HelloThread ht2 = new HelloThread( "morning" );
		HelloThread ht3 = new HelloThread( "to" );
		ht1.start();
		ht2.start();
		ht3.start();
		
		ht1.join();
		ht2.join();
		ht3.join();
		
		System.out.println( "You !" );
	}	
}
```