Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Producer Consumer Test-Advanced Computer Programming-Code, Lecture notes of Advanced Computer Programming

This is code file for a project related to Advanced Computer Programming course. It was submitted to Sarfaraz Khan at Alagappa University. It includes: Public, Class, Producer, Consumer, Test, Plate, Producer, Consumer, Private, Boolean, Available

Typology: Lecture notes

2011/2012

Uploaded on 07/11/2012

dhairya
dhairya 🇮🇳

5

(4)

31 documents

1 / 4

Related documents


Partial preview of the text

Download Producer Consumer Test-Advanced Computer Programming-Code and more Lecture notes Advanced Computer Programming in PDF only on Docsity! public class ProducerConsumerTest { public static void main(String[] args) { Plate c = new Plate(); Producer p1 = new Producer(c, 1); Consumer c1 = new Consumer(c, 1); p1.start(); c1.start(); } } class Plate { private int contents; private boolean available = false; public synchronized int get() { while (available == false) { try { wait(); } catch (InterruptedException e) { } } available = false; notifyAll(); return contents; } Docsity.com public synchronized void put(int value) { while (available == true) { try { wait(); } catch (InterruptedException e) { } } contents = value; available = true; notifyAll(); } } class Consumer extends Thread { private Plate Plate; private int number; public Consumer(Plate c, int number) { Plate = c; this.number = number; } public void run() { int value = 0; Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved