Added 7th program

This commit is contained in:
Aditya Tiwari
2026-01-29 14:26:42 +05:30
parent ebbb84749e
commit a4dfdeb2ee
4 changed files with 27 additions and 0 deletions

BIN
Inter7.class Normal file

Binary file not shown.

27
Inter7.java Normal file
View File

@@ -0,0 +1,27 @@
// 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);
}
}
}

BIN
TotalEarnings.class Normal file

Binary file not shown.

BIN
src/7Inter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB