synchronized (Foo.class) {
while (someCondition) {
try {
Foo.class.wait();
} catch (InterruptedException e) {
e.printStac
Wait method is used to suspend a current thread on an object. Wait method is not from thread class but from java.lang.Object
Notify method is used to wake the thread waiting on the object. Notify method is not from thread class but from java.lang.Object.
Interrupt method is used to to indicate the current thread that is should stop current job execution and can start other job. Interrupt method is from thread class.
Let see the real life example:
Consider Telephone as Object , Person as Thread. Suppose for instance A person is using Telephone and B person also wants to use the telephone but as A person i.e (Thread 1) is busy using it unless the work is done acquires a lock on telephone Object now B i.e(Thread 2) tries to use Telephone but as A has acquired lock on it B it goes into wait state until lock is released.