Open In App

Differences between wait() and join() methods in Java

The wait() and join() methods are used to pause the current thread. The wait() is used in with notify() and notifyAll() methods, but join() is used in Java to wait until one thread finishes its execution. wait() is mainly used for shared resources, a thread notifies other waiting thread when a resource becomes free. On the other hand join() is used for waiting a thread to die.

Similarities between wait() and join()



Difference between wait() and join() method

Let us understand the differences in a tabular form -:



wait() join()
It is a method of java.lang.Object class. It is a method of java.lang.
wait() method can be called by a synchronized block or method. It is used to stop the current thread.
wait() method is implemented for performing multi-thread-synchronization. It can be called either with synchronized and without synchronized context.

Its syntax is -:

public final void wait() throws InterruptedException

Its syntax is -:

public final void join() throws InterruptedException  

wait() method causes the thread to sleep until notify() and notifyAll() are called It can be used to add sequence among more than one thread
Article Tags :