Comment on Tutorial - wait(), notify() and notifyAll() in Java - A tutorial By Jagan



Comment Added by : princess

Comment Added at : 2011-11-30 12:09:38

Comment on Tutorial : wait(), notify() and notifyAll() in Java - A tutorial By Jagan
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. Hi : Pulkit Malviya .I think that book has coding
View Tutorial          By: Anand at 2012-11-04 14:13:50

2. what's the deffrint between "String[] [] Arra
View Tutorial          By: ahmad at 2009-08-24 03:01:11

3. one closing bracket ')' is required at while loop
View Tutorial          By: varsha Tambe at 2013-01-07 09:34:37

4. the ans is good.now i cleared my dout.and the exam
View Tutorial          By: siva at 2011-12-07 14:00:13

5. class Factorial
{
int fact(int

View Tutorial          By: soph at 2013-02-06 06:49:07

6. Really a great article!
I have some questio

View Tutorial          By: ron at 2010-03-30 01:37:12

7. What happens if applied to an integer array?
View Tutorial          By: SHUVO at 2015-07-01 21:14:16

8. gr8 tute dude.... ezy n nice..
View Tutorial          By: hErC!! at 2010-04-20 23:52:19

9. Good example...easy to read and understand...
View Tutorial          By: Codventure at 2009-09-11 00:07:06

10. guys you both are correct
but,java is impli

View Tutorial          By: vijay at 2011-09-08 12:12:48