sleep(long millis) 
          Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.The thread does not lose ownership of any monitors. yield() 
          Causes the currently executing thread object to temporarily pause and allow other threads to execute.至于为什么调用sleep,应该是根据程序的需要,使当前线程中止执行millis个毫秒,然后继续执行。关键在这一句:SLEEP does not lose ownership of any monitors.but YIELD allow other threads to execute.

解决方案 »

  1.   

    SLEEP does not lose ownership of any monitors不明白什么意思,monitors指什么东东呀。还有sleep使当前线程中止执行millis个毫秒时,难道此时其他线程就不能执行了吗?
      

  2.   

    sleep()是使当前进程中止一段时间,当前进程进入等待状态,当等待时间到时,进程自动运行.
    其它线程不受此影响,依旧按原有状态运行.
    所谓的monitor应该是监控器的意思吧.
    SLEEP does not lose ownership of any monitors
    是相对于suspend()和resume()方法(用来暂停线程或恢复线程。可以由线程自身在线程体中调用suspend()方法暂停自己,也可以在其他线程中通过线程实例调用suspend()方法暂停线程的执行。但是要恢复由suspend()方法暂停的线程,只能在其他线程中通过线程实例调用resume()方法。)
    suspend()应该算是lose ownership of any monitors
    yield()是中止当前进程,将执行的权力交给其它优先级相同的线程,直到其它优先级相同的线程全部执行完毕后再运行.
      

  3.   

    to super2000sea() :
        你的意思是当线程调用yeild()后,其它优先级相同的线程全部执行完毕后才能运行,如果有一个没完成,此线程就不能继续执行吗?
        那我想再问一下,什么才能算线程执行完毕,是run()执行完就是吗?
      

  4.   

    >你的意思是当线程调用yeild()后,其它优先级相同的线程全部执行完毕后才能运行,如果有一个没完成,此线程就不能继续执行吗?<
    不是吧,一个线程yield()之后,完全有可能又立即继续执行。
      

  5.   

    http://www.delfan.com/language/java/net/thread.html
    里面有很详细的讲解