package com.chengguo.线程; /** * 测试线程礼让 */ public class Demo_20200518002_Yield { public static void main(String[] args) { MyYield myYield = new MyYield(); new Thread(myYield, "a").start(); new Thread(myYield, "b").start(); } } class MyYield implements Runnable { @Override public void run() { System.out.println(Thread.currentThread().getName() + "线程开始执行……"); //线程礼让 Thread.yield(); System.out.println(Thread.currentThread().getName() + "线程停止执行……"); } }