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. Friends i m getting error while intrepreting the e
View Tutorial          By: Hanuman at 2014-02-04 14:14:00

2. works for me - thanks !!!!!
View Tutorial          By: Vaneeza at 2011-12-19 17:06:09

3. Fine,you r very straightforward I like that

View Tutorial          By: Shaiju at 2010-02-21 10:15:00

4. thanx. for this tutorial. i was having some doubt
View Tutorial          By: prabhash at 2011-09-06 10:15:19

5. The name OAK was changed to java because ,once the
View Tutorial          By: Sowminarayanan at 2010-11-28 06:17:42

6. import java.util.Scanner;
public class Swit

View Tutorial          By: srinath at 2013-04-28 10:17:24

7. Real Life example of using Volatile
*******

View Tutorial          By: Mayank at 2011-01-25 15:44:21

8. hi,.. i have used this code to sending sms. It see
View Tutorial          By: dana at 2008-08-05 03:38:48

9. Highly appreciatable.Excellent Docs.
View Tutorial          By: Debi P Naik at 2010-05-04 05:55:45

10. u doing good
View Tutorial          By: matsiko at 2009-04-14 08:05:00