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. Cool! Downloading the whole file with the HttpCon
View Tutorial          By: Luddite at 2010-06-26 12:26:26

2. The logo is a cup of coffee. Java is an island in
View Tutorial          By: kamal goduguluri at 2012-05-30 15:34:21

3. Awesome post....
View Tutorial          By: Zeeshan Ali Ansari at 2012-11-24 06:35:20

4. Thanks for the simple tutorial on hashmaps. I am n
View Tutorial          By: ipkwena at 2013-08-19 09:02:49

5. Very Helpful.
View Tutorial          By: nfahem at 2012-05-09 10:50:29

6. grazie!!!
View Tutorial          By: Egidio De Lorenzo at 2011-04-20 12:07:25

7. Yesterday afternoon, I tried a lot of different su
View Tutorial          By: Leo at 2011-07-26 04:19:15

8. short and very clear
View Tutorial          By: ramesh at 2009-07-22 22:27:25

9. You don't have to call the constructors. When you
View Tutorial          By: Watson at 2011-05-04 10:44:23

10. Its really helpfull to me thanks................
View Tutorial          By: AKS at 2013-08-10 06:27:43