Explain bout wait() and join method in Java thread
GIAN Tutorials
12:50 AM
Though both wait() and join() methods are used to pause the current thread and have a lot of similarities they have different purposes. One of the most obvious differences between the wait() and join() method is that former is declared in java.lang.Object class while join() is declared in java.lang.Thread class. This means that wait() is related to the monitor lock which is held by each instance of an object and join method is related to Thread itself. The wait() method is used in conjunction with notify() and notifyAll() method for inter-thread communication, but join() is used in Java multi-threading to wait until one thread finishes its execution. Another difference between wait() and join() method is that former must be called from synchronized method or block but later can be called without a synchronized block in Java. A good knowledge of differnet thread related methods e.g. start and run, wait and notify, join and yield goes a long way in writing robuts and correct multi-