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. nice one
View Tutorial          By: navyasri at 2012-05-02 04:41:10

2. It is very help full to me and very simple underst
View Tutorial          By: Reddymalla Babu Sircilla at 2013-02-22 08:28:22

3. please give me more information
View Tutorial          By: nandhini at 2012-09-22 03:49:11

4. thanks brother
View Tutorial          By: shakeel at 2012-09-12 16:21:03

5. Hi,
I want to run a bat file, below are the

View Tutorial          By: Rajshekar at 2011-10-28 06:07:06

6. Very useful tutorial. But if same code is executed
View Tutorial          By: Jitendra Kumar Mahto at 2011-08-12 15:10:14

7. I am developing a system for paying electric bill
View Tutorial          By: Isaya at 2007-03-26 01:11:59

8. I am executing this code using NetBeans6.9 and get
View Tutorial          By: Rohit at 2011-04-19 11:07:59

9. hey i need a sample program to draw table or grid
View Tutorial          By: pavi at 2012-10-15 04:27:27

10. thks for help...
View Tutorial          By: Peps at 2010-01-05 02:28:52