Thursday, June 12, 2025
HomeJavaDistinction between notify and notifyAll in Java

Distinction between notify and notifyAll in Java


            + ” goes to inform all or one thread ready on this object”);

            go = true; //making situation true for ready thread
            //notify(); // just one out of three ready thread WT1, WT2,WT3 will awoke
            notifyAll(); // all ready thread  WT1, WT2,WT3 will awoke
        }
     
    }
 
}

Output in case of utilizing notify
Thread[WT1,5,main] goes to attend on this object
Thread[WT3,5,main] goes to attend on this object
Thread[WT2,5,main] goes to attend on this object
Thread[NT1,5,main] goes to inform all or one thread ready on this object
Thread[WT1,5,main] is woken up
Thread[NT1,5,main] completed Execution
Thread[WT1,5,main] completed Execution

Output in case of calling notifyAll
Thread[WT1,5,main] goes to attend on this object
Thread[WT3,5,main] goes to attend on this object
Thread[WT2,5,main] goes to attend on this object
Thread[NT1,5,main] goes to inform all or one thread ready on this object
Thread[WT2,5,main] is woken up
Thread[NT1,5,main] completed Execution
Thread[WT3,5,main] is woken up
Thread[WT3,5,main] goes to attend on this object
Thread[WT2,5,main] completed Execution
Thread[WT1,5,main] is woken up
Thread[WT1,5,main] goes to attend on this object



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments