会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132413个问题

package com.itbjsxt.TestThread;

class  A implements Runnable{
    private Thread C;
    public A(Thread C){
        this.C = C;
    }

    @Override
    public void run() {
        for (int i =0;i<10;i++){
            System.out.println(Thread.currentThread().getName()+"A"+i);
            if (i ==5){
                try {
                    C.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
               e.printStackTrace();
            }

        }
    }
}
class B implements Runnable{
    @Override
    public void run() {
        for (int i =0;i<15;i++){
            System.out.println(Thread.currentThread().getName()+"B"+i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }

}
public class ThreadTest1 {
    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(new B());
        Thread t = new Thread(new A(t1));
        t.start();
        t1.start();
        for (int i =0;i<15;i++) {
            System.out.println(Thread.currentThread().getName() + " " + i);
            if (i ==2){
                t.join();

            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
请问一下老师,这里面用到的this.C和直接C.join()执行结果一样那两者有什么区别呢,我不是很理解this


JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程技术 8327楼
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 8329楼
Python 全系列/第二阶段:Python 深入与提高/(旧)坦克大战 8339楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器 8340楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637