礼让不一定成功,看CPU心情
package state;
public class 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()+"线程停止执行");
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-35834.html