/*
Write a program to illustrate inter - thread communication using wait(), notify() and notify all() method
*/
import java.io.*;
class q
{
String msg;
boolean flag;
q()
{
flag=false;
}
synchronized void get()
{
if(flag==false)
{
try
{
wait();
}//try
catch(InterruptedException e)
{
}//catch
}
flag=false;
System.out.println("Received Message"+msg);
notify();
}
synchronized void put(String x)
{
if(flag==true)
{
try
{
wait();
}
catch(InterruptedException e)
{
}//catch
}
msg = x;
flag = true;
if(msg.equalsIgnoreCase("Good Bye"))
System.exit(0);
notify();
}
}
class sender extends Thread{
q q1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s;
sender(q x)
{
q1 = x;
start();
}
public void run()
{
while(true)
{
System.out.println("Enter Message ");
try
{
s = br.readLine();
q1.put(s);
}
catch(IOException e)
{
}//catch
}//while
}//run
}
class receiver extends Thread
{
q q2;
receiver(q x)
{
q2 = x;
start();
}
public void run()
{
while(true)
{
q2.get();
}
}
}
class fourteen
{
public static void main(String args[])
{
q q4 = new q();
sender s = new sender(q4);
receiver r = new receiver(q4);
}
}
Write a program to illustrate inter - thread communication using wait(), notify() and notify all() method
*/
import java.io.*;
class q
{
String msg;
boolean flag;
q()
{
flag=false;
}
synchronized void get()
{
if(flag==false)
{
try
{
wait();
}//try
catch(InterruptedException e)
{
}//catch
}
flag=false;
System.out.println("Received Message"+msg);
notify();
}
synchronized void put(String x)
{
if(flag==true)
{
try
{
wait();
}
catch(InterruptedException e)
{
}//catch
}
msg = x;
flag = true;
if(msg.equalsIgnoreCase("Good Bye"))
System.exit(0);
notify();
}
}
class sender extends Thread{
q q1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s;
sender(q x)
{
q1 = x;
start();
}
public void run()
{
while(true)
{
System.out.println("Enter Message ");
try
{
s = br.readLine();
q1.put(s);
}
catch(IOException e)
{
}//catch
}//while
}//run
}
class receiver extends Thread
{
q q2;
receiver(q x)
{
q2 = x;
start();
}
public void run()
{
while(true)
{
q2.get();
}
}
}
class fourteen
{
public static void main(String args[])
{
q q4 = new q();
sender s = new sender(q4);
receiver r = new receiver(q4);
}
}
Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.
ReplyDeleterpa Training in Chennai
rpa Training in bangalore
rpa Training in pune
blueprism Training in Chennai
blueprism Training in bangalore
blueprism Training in pune
rpa online training
I recently came across your blog and have been reading along. I thought I would leave my first comment.
ReplyDeletejava training in chennai | java training in bangalore
java online training | java training in pune
java training in chennai | java training in bangalore
Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!
ReplyDeleteBlueprism training in marathahalli
Blueprism training in btm
Blueprism online training
Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
ReplyDeleteangularjs-Training in sholinganallur
angularjs-Training in velachery
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.good luck.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
Your good knowledge and kindness in playing with all the pieces were very useful.
ReplyDeleteJava training in Chennai
Java Online training in Chennai
Java Course in Chennai
Best JAVA Training Institutes in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Training
Java Online Training