Added 7th program
This commit is contained in:
BIN
Inter7.class
Normal file
BIN
Inter7.class
Normal file
Binary file not shown.
27
Inter7.java
Normal file
27
Inter7.java
Normal 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
BIN
TotalEarnings.class
Normal file
Binary file not shown.
BIN
src/7Inter.png
Normal file
BIN
src/7Inter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
Reference in New Issue
Block a user