public class threadT extends Thread {       public void run() {      
    
                 System.out.println("In run");                       yield();     
              
                 System.out.println("Leaving run");       }        public static void main(String args []) {   
    
                 (new threadT()).start();  
               
     }}
为什么在 yield()之后还会打印出Leaving run?不是已经停止了吗?谢谢

解决方案 »

  1.   

    yield
    public static void yield()暂停当前正在执行的线程对象,并执行其他线程。貌似没有其它线程哦   并且只是暂停,并不是停止哦
      

  2.   

    o,为啥会打印出Leaving run?
      

  3.   


    呵呵,为什么不呢?
    yield()暂停后,如果此时有其它线程,Leaving run会等到其它线程执行完了后再执行,如果没有其它线程,它就很快会执行啊
      

  4.   

    Causes the currently executing thread object to temporarily pause and allow other threads to execute. 
      

  5.   

    还有我摘录一本书上的原话给你,希望LZ 能明白当线程在运行中执行了Thread类的yield()静态方法,
    如果此时具有相同优先级的其他线程处于就绪状态,那么yield()方法
    把当前运行的线程放到可运行池中并使另一个线程运行.如果没有相同优先级的
    可运行线程,则yield()方法什么都不做....