00:00
/* N64 - how much earning in Mba app using wait,with parameters */ 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 N64 extends Thread{ public static void main(String[] args) { TotalEarning te = new TotalEarning(); te.start(); synchronized(te){ try{ te.wait(1); 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 STOP