您的位置:首页 > 编程语言 > Java开发

java多线程-join方法

2014-07-31 16:33 239 查看
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();
t2.start();
t1.join();

for(int x=0;x<80;x++)
{
System.out.println("mian....."+x);
}
System.out.println("over");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java