6 and 7th

This commit is contained in:
2026-01-29 14:27:35 +05:30
parent 00b45c11a4
commit 218550add2
2 changed files with 68 additions and 0 deletions

24
MovieBook.java Normal file
View File

@@ -0,0 +1,24 @@
// 7: write a java program for interthread communication using wait(), notify(), notifyAll()
class TotalEarnings extends Thread{
int total = 0;
public void run(){
synchronized(this){
for(int i=0;i<=10;i++){
total = total + 100;
}
this.notify();
}
}
}
public class MovieBook{
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);
}
}
}