重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java多线程-yield礼让

yield
礼让线程,让当前正在执行的线程暂停而不是阻塞线程
将线程从运行状态转入就绪状态
让cpu调度器重新调度

10年积累的成都网站设计、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有阳城免费网站建设让你可以放心的选择与我们合作。

public class n {

public static void main(String[]args)
{
    test t =new test();
    new Thread(t,"a").start();
    new Thread(t,"b").start();

}

}

class test implements Runnable{

public void run()
{
    System.out.println(Thread.currentThread().getName()+"-->start");
    Thread.yield();//礼让
    System.out.println(Thread.currentThread().getName()+"-->end");
}
}

例2:

public class n {

public static void main(String[]args)
{
    new Thread(()->
     {
        for(int i=0;i<5;i++)
        {
            System.out.println("a"+i);
        }
    }).start();

    for(int i=0;i<5;i++)
    {
        if(i%2==0)
        {
            Thread.yield();
        }
        System.out.println("b"+i);
    }
}

}

文章题目:java多线程-yield礼让
网页网址:http://cqcxhl.com/article/jjdisg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP