JAVA EXAMPLE PROGRAMS
wait Vs sleep methods
sleep(): It is a static method on Thread class. It makes the current thread into the "Not Runnable" state for specified amount of time. During this time, the thread keeps the lock (monitors) it has acquired.
wait(): It is a method on Object class. It makes the current thread into the "Not Runnable" state. Wait is called on a object, not a thread. Before calling wait() method, the object should be synchronized, means the object should be inside synchronized block. The call to wait() releases the acquired lock.
Discipline is just choosing between what you want now and what you want most.
-- Unknown Author
Few Random Java Examples
|Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.|