洛阳做网站哪家便宜,河池环江网站建设,网店开店流程步骤,网页制作软件html礼让线程#xff0c;让正执行的线程停止#xff0c;但不阻塞
将线程从运行状态转为就绪状态
让cpu重新调度#xff0c;礼让不一定成功#xff0c;看cpu心情
package com.wuming.state;public class TestYield {public static void main(String[] args) {MyYield myYield…礼让线程让正执行的线程停止但不阻塞
将线程从运行状态转为就绪状态
让cpu重新调度礼让不一定成功看cpu心情
package com.wuming.state;public class TestYield {public static void main(String[] args) {MyYield myYield new MyYield();new Thread(myYield,a).start();new Thread(myYield,b).start();}
}
class MyYield implements Runnable{/*** When an object implementing interface codeRunnable/code is used* to create a thread, starting the thread causes the objects* coderun/code method to be called in that separately executing* thread.* p* The general contract of the method coderun/code is that it may* take any action whatsoever.** see Thread#run()*/Overridepublic void run() {System.out.println(Thread.currentThread().getName()线程开始执行);Thread.yield();//礼让System.out.println(Thread.currentThread().getName()线程停止执行);}
}
a线程开始执行 b线程开始执行 a线程停止执行 b线程停止执行