继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

多线程-加入线程学习笔记

慕婉清0083722
关注TA
已关注
手记 322
粉丝 72
获赞 277

join(), 当前线程暂停, 等待指定的线程执行结束后, 当前线程再继续* join(int), 可以等待指定的毫秒之后继续    *             final Thread t1 = new Thread() {                public void run() {                    for(int i = 0; i < 50; i++) {                        System.out.println(getName() + "...aaaaaaaaaaaaaaaaaaaaaa");                        try {                            Thread.sleep(10);                        } catch (InterruptedException e) {                            e.printStackTrace();                        }                    }                }            };            Thread t2 = new Thread() {                public void run() {                    for(int i = 0; i < 50; i++) {                        if(i == 2) {                            try {                                //t1.join();                        //插队,加入                                t1.join(30);                        //加入,有固定的时间,过了固定时间,继续交替执行                                Thread.sleep(10);                            } catch (InterruptedException e) {                                e.printStackTrace();                            }                        }                        System.out.println(getName() + "...bb");                    }                }            };            t1.start();            t2.start();

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP