线程礼让
- 礼让不一定成功,看CPU心情~
/**
* 线程礼让
*/
public class MyYield implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + "线程开始执行");
Thread.yield();//线程礼让
System.out.println(Thread.currentThread().getName() + "线程停止执行");
}
}
public class MyMain {
public static void main(String[] args) {
MyYield myYield = new MyYield();
new Thread(myYield,"小康").start();
new Thread(myYield,"小妞").start();
}
}