Package test.run;
public class Traditionalthreadcommunication {
Private Business bus = new Business ();
public static void Main (string[] args) {
Final traditionalthreadcommunication a=new traditionalthreadcommunication ();
New Thread (New Runnable () {
public void Run () {
for (int i=1;i<=50;i++) {
A.bus.sub (i);
}
}
}). Start ();
for (int i=1;i<=50;i++) {
A.bus.maina (i);
}
}
Class business{
Private Boolean BS = true;
Public synchronized void sub (int i) {
while (!bs) {
try {
This.wait ();
} catch (Interruptedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
for (int j=1; j<10; J + +) {
System.out.println ("sub-thread" +j+ "Number of Cycles:" +i);
}
BS = false;
This.notify ();
}
Public synchronized void Maina (int i) {
while (BS) {
try {
This.wait ();
} catch (Interruptedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
for (int j=1; j<20; J + +) {
SYSTEM.OUT.PRINTLN ("Parent thread" +j+ "Number of Cycles:" +i);
}
BS = true;
This.notify ();
}
}
}
Java Synchronous Communication Mutex