Originally posted by jon ruane:
for example iv seen code like this:
object.wait();
thread.sleep();
but also:
wait();
sleep();
Hey John:
sleep is a static method in
Thread , so no need to call it upon a Thread object.Though its not wrong (will compile) and will have the same effect , that is putting the current thread to sleep for desired amount of time.
For wait I think the only thing necessary is that
you should call it from a syncronized context , that is you have to aquire a lock before you call it.
As its a public method in Object class , you can call it from the code directly or using new Object().wait();
Only thing is that the current thread would go to the wait set of the object whose lock you have acquired.