首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java thread小疑点

2012-01-01 
java thread小问题。提问在注释那里Java codepublic class MyFile implements Runnable{public void run()

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!!

热点排行