Java中的线程让步Thread.yield()

来源:互联网 发布:网络扫黄打非工作个人 编辑:程序博客网 时间:2024/05/16 00:36
class MyThead implements Runnable{public void run(){for (int i = 1; i <= 100; i++){System.out.println("thread======>" + Thread.currentThread().getName());if (i >= 90){Thread.yield();System.out.println(i + "     让路 给thread======>" + Thread.currentThread().getName());}}}}public class TheadMain{public static void main(String[] args){MyThead myThead = new MyThead();Thread thread1 = new Thread(myThead, "AAA");Thread thread2 = new Thread(myThead, "BBB");thread1.start();thread2.start();}}

原创粉丝点击