Answered step by step
Verified Expert Solution
Question
1 Approved Answer
**THIS IS IN JAVA** Person.java public class Person { private String name; private int age; public Person() { name = ; age = 0; }
**THIS IS IN JAVA**
Person.java
public class Person { private String name; private int age;
public Person() { name = ""; age = 0; } public Person(String s, int i) { name = new String(s); age = i; }
public Person(Person p) { this.name = p.name; this.age = p.age; }
public String getName() { return name; } public int getAge() { return age; } public void setAge(int a) { age = a; } public void setName(String n) { name = n; } public String toString() { return ("Name: " + name + " Age: " + age); } }
Task To construct an example to demonstrate the producer/consumer problem and then adjust the example to solve the producer/consumer problem. Method Download Person.java from Canvas. Don't change the code. Part 1 In this part you will illustrate 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. Create classes as follows: PersonBuffer - class to represent one Person object with a get and set method Producer class - produces 10 Person objects and writes them successively to a personBuffer, which is a data member Consumer class - consumes 10 Person objects successively from a personBuffer, which is a data member Producer ConsumerTest-sets up a producer and consumer thread to execute using a shared PersonBuffer When you run Producer Consumer Test you should see output that prints every time the shared PersonBuffer is written to or read from (see example printout on CourseWeb) Part 2 Make copies of your files from Part 1 and make changes to correct the problem (see example on Canvas). You should use synchronization, a shared boolean and waitotifyAll. Notes For the threads, only use the syntax we have used in class and in examples. Do not use any high-level classes or data structures. You may need to synchronize methods or parts of| methods. When you synchronize part of a method you use the syntax: synchronized (name of object to synchronize on) { code } Task To construct an example to demonstrate the producer/consumer problem and then adjust the example to solve the producer/consumer problem. Method Download Person.java from Canvas. Don't change the code. Part 1 In this part you will illustrate 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. Create classes as follows: PersonBuffer - class to represent one Person object with a get and set method Producer class - produces 10 Person objects and writes them successively to a personBuffer, which is a data member Consumer class - consumes 10 Person objects successively from a personBuffer, which is a data member Producer ConsumerTest-sets up a producer and consumer thread to execute using a shared PersonBuffer When you run Producer Consumer Test you should see output that prints every time the shared PersonBuffer is written to or read from (see example printout on CourseWeb) Part 2 Make copies of your files from Part 1 and make changes to correct the problem (see example on Canvas). You should use synchronization, a shared boolean and waitotifyAll. Notes For the threads, only use the syntax we have used in class and in examples. Do not use any high-level classes or data structures. You may need to synchronize methods or parts of| methods. When you synchronize part of a method you use the syntax: synchronized (name of object to synchronize on) { code }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started