In java demonstrate the producer/consumer problem by setting up two threads that use a shared buffer. Use Threads and/or Runnable objects. Do not use synchronized, wait, notifyAll or a boolean to control access to the shared buffer. use Rect.java

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In java demonstrate the producer/consumer problem by setting up two threads that use a shared buffer. Use Threads and/or Runnable objects. Do not use synchronized, wait, notifyAll or a boolean to control access to the shared buffer. use Rect.java

Create classes as follows:

 

RectangleBuffer – class to represent one Rect object with a get and set method

Producer class – produces 10 Rect objects and writes them successively to a RectangleBuffer, which is a data member of the class

Consumer class – consumes (reads) 10 Person objects successively from a RectangleBuffer, which is a data member of the class

ProducerConsumerTest – sets up a producer and consumer thread to execute using a shared RectangleBuffer

 

Rect.java

public class Rect implements Comparable<Rect>
{
    private double length;
    private double width;

    public Rect()
    {
        length = 0.0;
        width = 0.0;
    }

    public Rect(double l, double w)
    {
        length = l;
        width = w;
    }
    
    public Rect(Rect r) {
        this.length = r.length;
        this.width = r.width;
    }
    
    public double getLength()
    {
        return length;
    }

    public double getWidth()
    {
        return width;
    }

    public void setLength(double l)
    {
        length = l;
    }

    public void setWidth(double w)
    {
        width = w;
    }

    public double calcArea()
    {
        return length * width;
    }

    public boolean equals(Rect r)
    {
        boolean temp = false;
        if ((this.length == r.getLength()) && (this.width == r.getWidth()))
            temp = true;

        return temp;
    }

    public int compareTo(Rect r) { 
        if (this.calcArea() < r.calcArea())
            return -1;
        else if (this.calcArea() > r.calcArea())
            return 1;
        else
            return 0;

    }
 
    public String toString()
    {
        return "[Length = " + length + " Width = " + width+ "]";
    }
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY