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's really Nice Clock
View Tutorial          By: Mido at 2007-09-09 08:45:49

2. Please tell me how to display the contents of stac
View Tutorial          By: Senthil at 2014-05-21 21:44:05

3. please give some examples of postfix and infix.
View Tutorial          By: john mark at 2012-10-07 13:55:04

4. nice!!!!
View Tutorial          By: svk at 2013-01-17 19:59:05

5. thanks i am fresher to j2me i understand the conce
View Tutorial          By: anusha at 2010-04-20 00:32:10

6. i have run the code successfully but it does not s
View Tutorial          By: amrish at 2010-12-11 07:00:28

7. this is the output i get.
Help me.
<

View Tutorial          By: shubham saxena at 2014-04-01 17:06:00

8. I got the sample and the test working. Thanks a lo
View Tutorial          By: Trishul at 2009-10-26 07:32:57

9. Excellent.. simple and too good to understand
View Tutorial          By: venkat at 2010-05-11 00:30:02

10. Thanks a ton! :)
View Tutorial          By: Prateek at 2015-03-12 11:40:08