标签:线程调度 使用 i++ oid string runnable for str getname
当调用Thread.yield()函数时,会给线程调度器一个当前线程愿意让出CPU使用的暗示,但是线程调度器可能会忽略这个暗示
public class YieldDemo { public static void main(String[] args) { Runnable yieldTask = new Runnable() { @Override public void run() { for (int i = 1; i <= 10; i++) { System.out.println(Thread.currentThread().getName() + i); if (i == 5) { Thread.yield(); } } } }; Thread t1 = new Thread(yieldTask, "A"); Thread t2 = new Thread(yieldTask, "B"); t1.start(); t2.start(); } }
标签:线程调度 使用 i++ oid string runnable for str getname
原文地址:https://www.cnblogs.com/vingLiu/p/10665185.html