package com.Java;
//线程礼让 礼让不一定成功
public class TestYield {
public static void main(String[] args) {
MyYield yield = new MyYield();
new Thread(yield, "a").start();
new Thread(yield, "b").start();
}
}
class MyYield implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + "开始执行");
Thread.yield();//礼让
System.out.println(Thread.currentThread().getName() + "停止执行");
}
}
线程礼让 Thread.yield(); 礼让不一定成功
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240825082459112-376424429.jpg)