import java.lang.Thread;
//让出CPU,给其他进程执行机会
public class ThreadTest6_Yield{
public static void main(String[] args){
MyThread3 t1 = new MyThread3("A-----");
MyThread3 t2 = new MyThread3("B=====");
t1.start();
t2.start();
}
}
class MyThread3 extends Thread {
MyThread3(String s){
super(s);
}
public void run(){
for(int i=1;i<=100;i++){
System.out.println(getName()+" : "+i);
if(i%10==0)
yield();
}
}
}
这段代码运行的结果为什么不是10个A和10个B交叉输出呢?
慕丝7291255
慕的地8271018
相关分类