提问在注释那里public class MyFile implements Runnable{
  public void run()
 { 
  while (true)
  { 
    try{ 
       FileReader fr=new FileReader(new File("a.txt")) ;
       String line=fr.readLine(); System.out.println(line); 
       }catch(IOException err) {
        
       } 
       Sleep(1000);//这里为什么要用Thread.sleep。这个thread是哪里来的?是从Object继承来的吗? 
   } 
}求大虾解答。

解决方案 »

  1.   

    Thread类中的sleep()是一个静态方法public static void sleep(long millis,
                             int nanos)
                      throws InterruptedException
    Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors. 所有类都是Object类,Thread也不例外
      

  2.   

    使用 Sleep(1000);是为了在循环的时候,都暂停1000毫秒,这样可以更好的看到程序输出,不至于一下子刷出一屏来,Thread是继承自Object!!