00:00
N63mBA.png
/* N63mBA - how much earning in Mba app using wait, notify, notifyAll*/ /* 1. runnig thD lock ko release kar deyta hai aur waiting ya pause state me chala jata hai aur dusra thD complete hota hai to wo ek notification send karta hai notify - wait ko aur wo waiting thD ko invoke kar deyta hai notifyAll - sare thD ko invoke kar deyta hia. */ class TotalEarning extends Thread{ int total = 0 ; public void run(){ synchronized(this){ for(int i=1;i<=10;i++){ total=total+100; } this.notify(); // send to - wait - release lock - main aquare lock } } } public class N63mBA extends Thread{ public static void main(String[] args) { TotalEarning te = new TotalEarning(); te.start(); synchronized(te){ try{ te.wait(); System.out.println("total earning = "+ te.total +" Rs."); } catch(InterruptedException e){ e.printStackTrace(); } } } } /* ramannegi@Ramans-MacBook-Pro x % javac N63mBA.java ramannegi@Ramans-MacBook-Pro x % java N63mBA total earning = 1000 Rs. */
Home PREVIOUS NEXT