ITeye博客

线程学习之join()

arne3166 · 2010-10-14 11:44 · 多线程 · 编程语言 · Markdown

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 !" );
	}	
}

评论(0)

暂无评论。

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