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. it is super
View Tutorial          By: vinod at 2011-09-03 04:06:02

2. thanks!
View Tutorial          By: leny at 2014-12-09 04:00:44

3. what if the delimiter is "(quotation mark)?
View Tutorial          By: hiakoto at 2013-02-18 16:15:20

4. now I know what isset is for, thank you very much
View Tutorial          By: Anonymous at 2010-12-23 20:43:29

5. I got intersting idea about gauge,thanks...
View Tutorial          By: Marimuthu at 2009-07-20 00:56:27

6. Hi everybody,
cn u plz mail me the working

View Tutorial          By: Srijita at 2011-11-28 06:10:03

7. as in property we set the value and then retrieve
View Tutorial          By: Deep at 2011-03-18 21:00:54

8. Its working perfectly for me.Thanks so much for pr
View Tutorial          By: Sunpenn at 2009-10-13 00:53:09

9. THANK YOU.. YO SO HELP ME :D
View Tutorial          By: xgamer at 2015-08-06 06:45:52

10. nice and simple information...............
View Tutorial          By: sengadu at 2010-07-24 07:43:29