黑马程序员技术交流社区
标题:
yield让出cpu礼让线程
[打印本页]
作者:
zhaokai123456
时间:
2016-5-4 23:31
标题:
yield让出cpu礼让线程
package com.heima.threadmethod;
public class Demo6_Yield {
/**
* yield让出cpu礼让线程
*/
public static void main(String[] args) {
new MyThread().start();
new MyThread().start();
}
}
class MyThread extends Thread {
public void run() {
for(int i = 1; i <= 1000; i++) {
if(i % 10 == 0) {
Thread.yield(); //让出CPU
}
System.out.println(getName() + "..." + i);
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2