Wait this thread to die;
将A线程加入到B线程中,直到A线程结束,B线程继续运行。
代码实例:
View Code
1 public class TestJoin{ 2 public static void main(String[] args){ 3 JoinThread jt=new JoinThread(); 4 Thread t=new Thread(jt); 5 t.start(); 6 int i=0; 7 while(i<200){ 8 if(i<100){ 9 try{ 10 t.join(); 11 }catch(Exception e){ 12 e.printStackTrace(); 13 } 14 } 15 System.out.println("main thread:"+i++); 16 } 17 } 18 } 19 20 class JoinThread implements Runnable{ 21 public void run(){ 22 int i=0; 23 while(i<100){ 24 System.out.println(Thread.currentThread().getName()+i++); 25 } 26 } 27 }
当Main函数中的循环变量i小于100时,JoinThread运行,直到JoinThread运行完毕,Main线程继续运行
转载于:https://www.cnblogs.com/stansonwilliam/archive/2012/10/26/2740467.html
原文链接:https://blog.csdn.net/weixin_30342827/article/details/94932625
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~