阅读背景:

150_多线程(Join方法)

来源:互联网 

/*
join:
当A线程履行到了B线程的join办法时,A就会期待。
等B线程都履行完,A才会履行。
join可以用来临时参加线程履行
*/
class Demo implements Runnable{
	public void run(){
		for(int x = 0;x < 70;x++){
			System.out.println(Thread.currentThread().getName()
			+"...."+x);
		}
	}
}
class JoinDemo{
	public static void main(String[] args)throws Exception{
		Demo d = new Demo();
		Thread t1 = new Thread(d);
		Thread t2 = new Thread(d);
		
		t1.start();
		t1.join();
		t2.start();
		
		for(int x=0;x<80;x++){
			System.out.println("main.."+x);
		}
		System.out.println("over");
	}
}
/*
join:
当A线程履行到了B线程的join办法时,A就会期待。
等B线程都履行完,A才会履




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: