This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In generic terms when you call sleep(1000) this means that the thread on which you are executing it will sleep down for 1000 milleseconds, go to sleep state and then go to Ready to Run state after the defined time in the constructor and when you will called yield methord then the thread will immediately go to Ready to Run state and wait for it chance to be get executed.
In Nutshell -:
***sleep(1000) -: immediately get the current running thread blocked and go to Ready to Run state after the defined time in the constructor and wait for its cance to be get executed.
***yield -: immediately take the thread on which it is called to Ready to Run state and wait for it chance to be executed , it does not get Blocked.
krason the code is ok and i got the o/p one one two two....thats fine.... but my doubt is can we call the sleep method directly like sleep(1000); but sleep and yield method are static methods present in Thread class...
Joined: Aug 05, 2005
Yes it should be correct. JLS states that a class inherits all super class methods that are not private (and with package for default).