producer and concumer Interface program

producer and concumer Interface program

I need producer and concumer Interface program

View Answers

October 22, 2010 at 2:30 PM

Hi Friend,

Try the following code:

import java.util.*;
class Multithreading {
int val;
boolean value = false;
synchronized int get() {
if(!value)
try {
wait();
} catch(Exception e) {
System.out.println(e);
}
System.out.println("Get: " + val);
value = false;
notify();
return val;
}
synchronized void put(int val) {
if(value)
try {
wait();
}catch(Exception e) {
System.out.println(e);
}
this.val = val;
value = true;
System.out.println("Put: " + val);
notify();
}
}
class Producer implements Runnable {
Multithreading th;
Producer(Multithreading th) {
this.th = th;
new Thread(this, "Producer").start();
}
public void run() {
int i = 0;
while(i<=50) {
th.put(i++);
}
}
}

class Consumer implements Runnable {
Multithreading th;
Consumer(Multithreading th) {
this.th = th;
new Thread(this, "Consumer").start();
}
public void run() {
while(true) {
th.get();
}
}
}
class ProducerConsumer {
public static void main(String args[]) {
Multithreading th = new Multithreading();
new Producer(th);
new Consumer(th);
}
}

For more information, visit the following link:

http://www.roseindia.net/java/thread/InterthreadCommunication.shtml

Thanks









Related Tutorials/Questions & Answers:
producer and concumer Interface program
producer and concumer Interface program  I need producer and concumer Interface program   Hi Friend, Try the following code:ADS...; System.out.println("Put: " + val); notify(); } } class Producer implements Runnable
producer and concumer problem
producer and concumer problem  Write aprogram by using the implementation of the Producer/Consumer problem. the programe ask user to write array... press stop and press start again the program produce adifferent value 1 0 0 1 0
Advertisements
program and Interface builder
program and Interface builder  Hi, I'm just getting started in iPhone development, If someone could please suggest a good criterion for when to use a nib to lay out UI elemennts and when to layout the UI elements
interface
interface   what is the use of marking interface
Interface
Interface  Can Any one Give the exact program explanation for Interface in java? and want to know why they used interface instead of multiple inheritance? Thanks in advance   An interface is one which has abstract
interface.
interface.  Write short note on interface.   Please visit the following link: Java Interface
interface
interface  will the interface implements a interface   Hi Friend, No. Interface can extends another interface but cannot implements it, because interface will not contain the implementation. Thanks
Write an event driven program to perform the arithmetic operations as shown in the interface
Write an event driven program to perform the arithmetic operations as shown... the java programming code for that question. my question is here: Q. Write an event driven program to perform the arithmetic operations as shown
INTERFACE
INTERFACE  how interface support multiple inheritance in java
interface
interface   Hi I have interface in that interface 3 methods are there , after some days client said that,i want to add one more method in that interface ,so how can add 4 method so that the implemented class did not affect
interface
interface  can we extend interface?   Hi Friend, Yes an interface can be extended by other interface like using extends keyword interface A{ } interface B extends A{ } For Example: interface IntefaceA { void
interface
interface  what the use of interface?   An interface is one... variables.Any class can implement(inherit)the interface and make use... is achieved by using the interface (by implementing more than one interface at a time
interface
interface  What is marker interface ?? what is its use in java programming?? is this us in programming ??Explain is implementation with code
interface
interface  develop a library interface which has drawbook(),returnbook()(with fine),checkstatus() and reservebook() methods.all the methods tagged with public
interface
interface  develop a library interface which has drawbook(),returnbook()(with fine),checkstatus() and reservebook() methods.all the methods tagged with public
interface
interface  why do we need interface in java..if it`s usefull for to obtain multiple inheritance in the sense how it gonna be achieved...and i can...)...the y we need interface...THis is question often i heard from my developer
Interface
Interface  I need to implement the interface without overriding its method and also don't use abstract class for this. How to do
interface
interface  What is the exact use of interface in real time scenario? some people says that interface provides multiple inheritance. Is it true...; Through interface, we can achieve the multiple inheritance. Java does
Interface
Interface  1.Create an interface names ShapeInterface that has two... class a.Rectangle that uses the interface b.Circle that uses the interface and abstract class   interface ShapeInterface{ int l=0,b=0; public
Interface
Interface  1.Create an interface names ShapeInterface that has two... class a.Rectangle that uses the interface b.Circle that uses the interface and abstract class   interface ShapeInterface{ int l=0,b=0; public
Interface
Interface  Declare an Interface called property containting a method compute price to compute &return the price.The inerface is to be implemented by follwaing two class (1)Bungalow&(2)Flat both the lasses have following
ModuleNotFoundError: No module named 'Producer-Consumer'
ModuleNotFoundError: No module named 'Producer-Consumer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Producer-Consumer' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'kinesis-producer'
ModuleNotFoundError: No module named 'kinesis-producer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'kinesis-producer' How to remove the ModuleNotFoundError: No module
EJB remote interface
EJB remote interface       The program given below describes  the way of creating a remote interface in EJB. The meaning of Remote interface in terms of Ejb is the java source file
ModuleNotFoundError: No module named 'netbox-kafka-producer'
ModuleNotFoundError: No module named 'netbox-kafka-producer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'netbox-kafka-producer' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'plenario-stream-kinesis-producer'
ModuleNotFoundError: No module named 'plenario-stream-kinesis-producer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'plenario-stream-kinesis-producer' How to remove
ModuleNotFoundError: No module named 'plenario-stream-kinesis-producer'
ModuleNotFoundError: No module named 'plenario-stream-kinesis-producer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'plenario-stream-kinesis-producer' How to remove
ModuleNotFoundError: No module named 'kafka-avro-producer-topkrabbensteam'
ModuleNotFoundError: No module named 'kafka-avro-producer-topkrabbensteam'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'kafka-avro-producer-topkrabbensteam' How to remove
ModuleNotFoundError: No module named 'kafka-metrics-producer-topkrabbensteam'
ModuleNotFoundError: No module named 'kafka-metrics-producer-topkrabbensteam'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'kafka-metrics-producer-topkrabbensteam' How
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
Program
Program  Define Interface Insurance with methods: details()(name, types of services), no. of branches(), No. of customers(), annual_income(). Implement these methods in its Implementation class LIC, National, BajajAlliance
What is an interface?
What is an interface?  What is an interface
Can an Interface implement another Interface?
Can an Interface implement another Interface?   Hi, Can an Interface implement another Interface? Thanks
Can an Interface extend another Interface?
Can an Interface extend another Interface?   Hi, Can an Interface extend another Interface? thanks
ServletRequest interface
ServletRequest interface   What is new in ServletRequest interface
collection interface
collection interface  methods of collection interface and their description with example program?   Please visit the following links: http://www.roseindia.net/java/jdk6/Collection-Interfaces.shtml http
collection interface
collection interface  methods of collection interface and their description with example program?   Please visit the following links: http://www.roseindia.net/java/jdk6/Collection-Interfaces.shtml http
program
program  any program of hotel or school management
program
program  program of jdbc using ms access for creating table
program
program  write a html program in show table and this word in box
program
program  write a program different between to dates in terms of days in java
program
program  write a javascript program to create a application form with validation
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
program
program  write a program reversee a string. input-hi this is roseindia output-roseindia is this hi
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
program
program   An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes
program
program  write a java program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
program
program  Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder

Ads