读书人

java thread小疑点

发布时间: 2012-01-01 23:10:55 作者: rapoo

java thread小问题。
提问在注释那里

Java code
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继承来的吗?    } }

求大虾解答。

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

读书人网 >J2SE开发

热点推荐