A Java program has k ItemProducer and k ItemConsumer threads sharing the same object of a subclass of class Buffer (see file Buffer.java). Every producer thread writes n times an object of class Item into the Buffer object, and every consumer thread reads n times an Item object from an OnePlaceBuffer instance.
In task 1, you have to complete class OnePlaceBuffer. In task 2, you complete class BoundedBuffer.
Class OnePlaceBuffer allows to store and retrieve an arbitrary instance of class Object. An instance of OnePlaceBuffer allows to store zero or one objects at any time.
Complete class OnePlaceBuffer. In particular, you should:
Investigate your program regarding its safety and liveness properties.
Notice that due to the potential delays of the messages of the threads,
the output of the program at the console can be confusing.
Introduce loose coupling between the producers and consumers in the program of task 1. Extend abstract class Buffer by a BoundedBuffer class. An instance of this class allows to store m Item objects. If the buffer is full then threads attempting to write must be blocked. If the buffer is empty then threads attempting to read must be blocked.
In particular, you should:
Investigate your program regarding the coupling of the producer and consumer threads. Notice that due to the potential delays of the messages of the threads, the output of the program at the console can be confusing.
All your sources files should be belong to package edu.nyu.oop.threads.cooperation.
This assignment is worth a maximum of 100 points.
You will need to demonstrate your assignment to a grader to receive a
grade. In addition, you will need to show the grader the following:
The above should be packaged in a jar file called a2.jar. For creating
a jar file you can run the following command in from DOS prompt in your
jar cvf a1.jar * . The jar helper contains additional information on
this Java utility.