27 lines
527 B
Java
27 lines
527 B
Java
// 7. Write a java program for inter thread communication using wait(), notify(), notifyall()
|
|
class TotalEarnings extends Thread{
|
|
int total = 0;
|
|
public void run(){
|
|
synchronized(this){
|
|
for(int i=1; i<=10;i++){
|
|
total = total + 10;
|
|
}
|
|
this.notify();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public class Inter7 {
|
|
public static void main(String[] args) throws InterruptedException{
|
|
TotalEarnings te = new TotalEarnings();
|
|
te.start();
|
|
synchronized(te){
|
|
te.wait();
|
|
System.out.println("Total earnings: "+te.total);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|