public class TestYield implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {

            if ("Thread-0".equals(Thread.currentThread().getName())){
                if (i==0){
                    Thread.yield();
                }
            }  System.out.println(Thread.currentThread().getName() + " : " + i);
        }
    }

    public static void main(String[] args) {
        Thread t=new Thread(new TestYield());
        Thread t2=new Thread(new TestThread());
        t.start();
        t2.start();
    }
}

//我的没有让步是因为什么


相关课程:JAVA 全系列>第二阶段:JAVA 基础深化和提高>多线程技术>线程的使用_线程让步

课程分类

尚新途微信公众号

尚新途微信小程序

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