其他分享
首页 > 其他分享> > 十五、线程礼让

十五、线程礼让

作者:互联网

代码:

public class ThreadYield implements Runnable{

    public static void main(String[] args) {
        ThreadYield threadYield = new ThreadYield();
        new Thread(threadYield,"A").start();
        new Thread(threadYield,"B").start();
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始");
        Thread.yield();
        System.out.println(Thread.currentThread().getName()+"线程结束");
    }
}

结果:

  礼让成功:

  

  礼让失败:

  

标签:ThreadYield,threadYield,Thread,线程,十五,new,礼让
来源: https://www.cnblogs.com/epiphany8/p/16271479.html