The call of wait() method on the object will hold the execution of the currently running thread until some other thread calls the notify() or notifyAll() method on the same object. The currently running thread will release the object monitor of the object on which the wait() method is invoked/called. Then some other thread can acquire the object monitor and continue its work with that object. The thread (that owns the object monitor) will call the notify() or notifyAll() method to notify the threads that are waiting on the on that object to inform that “the object monitor will be released soon and get ready to acquire it“.
wait() method should be called in a synchronized context. that means either in synchronized method or synchronized block.
since the wait() method is inherited from the Object class, it can be invoked on any java object(that is directly or indirectly inherited from Object class)
The join() method belongs to the Thread class. therefore join() method can be invoked only on the Thread objects. The join() method is used to postpone the execution of the currently running thread after the execution of some other thread.
ThreadA threadA = new ThreadA(); threadA.join();
Here the currently running thread (lets say it as the main thread) will hold the execution until the threadA completes. Once the threadA is completed, the waiting/sleeping thread (the main thread) will be resumed its execution. Simply the main thread will be resumed once the threadA is dead(after completing the run method)
Thread.sleep causes the current thread to suspend execution for a specified time period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system.