// t is a thread // is line 5 and line 6 are the same ? public void run() { try { while(val < 5) { System.out.println(val); Thread.sleep(500); // line 5 //t.sleep(500); // line 6
sleep is a static method - so *yes* it is the same. (sleep always acts on the currently executing thread). It's nicer to refer to static methods thru the class name ie. Thread.sleep()