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