Comment on Tutorial - wait(), notify() and notifyAll() in Java - A tutorial By Jagan



Comment Added by : princess

Comment Added at : 2011-11-30 12:11:57

Comment on Tutorial : wait(), notify() and notifyAll() in Java - A tutorial By Jagan
hope this may help u

class product
{
int contents=0;
boolean available = false;
synchronized int get()
{
if(available==false)
try
{
wait();
}
catch(InterruptedException e)
{
System.out.println("InterruptException caught");
}

System.out.println("consume:"+contents);
System.out.println("hello");
available=false;
notifyAll();
return contents;
}
synchronized void put(int num)
{
if(available==true)
try
{
wait();
}
catch(InterruptedException e)
{
System.out.println("InterruptedException caught");
}
contents=num;
System.out.println("produce:"+contents);
System.out.println("Welcome");
notifyAll();
}
}
class producer extends Thread
{
product p;
producer(product p)
{
this.p=p;
this.start();
}
public void run()
{
int i=0;
p.put(++i);
}
}
class consumer extends Thread
{
product p;
consumer(product p)
{
this.p=p;
this.start();
}
public void run()
{
p.get();
}
}
public class interthreadcon
{
public static void main(String[] args)
{
product s = new product();
new producer(s);
new consumer(s);
}
}


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. I want java
View Tutorial          By: A.S.Vtihyatharan at 2009-12-01 03:25:36

2. Simple and effective example
View Tutorial          By: Anand at 2009-02-05 00:18:10

3. hi.....
if we have number of fieldsl ike na

View Tutorial          By: shailesh at 2011-12-15 07:10:34

4. Thank you for your help !
View Tutorial          By: vadym at 2010-03-03 06:35:01

5. Plz. help me in getting code to read messages usin
View Tutorial          By: Jaydatta at 2009-04-03 20:58:57

6. Nice Example. Gives very clear idea.
View Tutorial          By: Larsen at 2013-09-14 02:29:24

7. lllllllllllllllllllllllllllllike
View Tutorial          By: duck at 2015-04-10 19:19:47

8. Hello
I installed Android in eclipse...only

View Tutorial          By: amit kumar at 2012-01-19 11:04:55

9. Can you give me an example to create InetAddress f
View Tutorial          By: Vaibhav at 2009-12-15 23:37:49

10. why it is( ((year % 4 == 0) && !(year % 10
View Tutorial          By: Jai Shankar K at 2012-04-08 10:15:56