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



Ask a Question

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. really helpfull :) thanks
View Tutorial          By: Jagan at 2014-12-09 10:16:56

2. really understandable
but 'm expecting with

View Tutorial          By: rajkumar at 2008-03-14 03:53:21

3. What about for an iPad and iPhone!
View Tutorial          By: Kamalakannan at 2012-09-21 06:10:39

4. good example tnq...........
View Tutorial          By: SaidiReddy at 2012-06-09 12:03:09

5. w0w amazing
View Tutorial          By: elvin at 2009-01-05 01:00:13

6. I do not understand this line:
Map.Entry me

View Tutorial          By: hap Og at 2011-11-03 01:42:33

7. what if i want to create a digital signature on th
View Tutorial          By: Chandra at 2012-06-10 00:52:15

8. I have a site fully based on php and mysql.The log
View Tutorial          By: titus at 2011-06-14 00:52:30

9. Thanks for the tutorial.

One questi

View Tutorial          By: Stephen at 2012-06-09 06:36:23

10. hi i have doubt in strlen()........pls explain how
View Tutorial          By: ranjith at 2010-04-18 21:50:17