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() + "線程中止執行……"); } }