线程中的yield()方法????
public class Thread4 extends Thread{
public Thread4() {
}
public void run(){
for(int i=1;i<=10;i++){
System.out.println(getName()+":"+i);
yield(); //x1
try{
sleep(1000);
}catch(InterruptedException ie){}
}
}
public static void main(String[] args) {
Thread4 t1=new Thread4();
Thread4 t2=new Thread4();
t1.start();
t2.start();
}
}
通过几次运行以上程序发现 yield()有无好象对程序的执行结果和效率没什么影响.
我知道 yield()方法使当前运行的线程对象退出运行状态,使其他线程得以运行.
请高手指点一下有无yield()方法的区别在哪里???谢谢了