线程礼让
作者:互联网
1 package 多线程练习; 2 3 /* 4 线程礼让不一定每次都成功 看CPU调度 5 */ 6 public class ThreadYieldTest { 7 public static void main(String[] args) { 8 Runnable rb1 = ()->{ 9 System.out.println(Thread.currentThread().getName()+" 开始执行"); 10 Thread.yield(); // 线程礼让 11 System.out.println(Thread.currentThread().getName()+" 执行结束"); 12 }; 13 14 new Thread(rb1,"线程A").start(); 15 new Thread(rb1,"线程B").start(); 16 } 17 }
输出结果
标签:Thread,currentThread,System,rb1,线程,礼让 来源: https://www.cnblogs.com/wooroc/p/15807305.html