Question: Programming Project 2 1. Introduction In this project, you will write a program to simulate producer-consumer problem using bounded buffer whose size is 10. (this

 Programming Project 2 1. Introduction In this project, you will write

a program to simulate producer-consumer problem using bounded buffer whose size is

Programming Project 2 1. Introduction In this project, you will write a program to simulate producer-consumer problem using bounded buffer whose size is 10. (this means the buffer only can store 10 messages.) For this, there will be one program creating two threads (one for producer and the other for consumer) which act as different processes. After 15 seconds of running, the program (both producer and consumer threads) should be terminated gracefully without any error. 2. Producer Thread Producer thread generates integers (014) which are treated as a message. The thread first checks if the buffer is full or not. At this moment, make sure the producer thread always waits random period of time (10100 milliseconds) before checking the buffer. This is to create randomness in the program execution. If the buffer is full, it waits another random period of time (10-100 milliseconds). If the buffer is not full, then it places an integer (014) in sequence into the buffer. "In sequence, herein, means first the producer places in the buffer. Next time, it produces 1, 2, 3, ... and so on until it produces 14 and places it in the buffer. Once the producer places 14 in the buffer, it produces 0 again. Every time producer thread places a message and integer) in the buffer, it makes a log in the file (say, producer.txt) in the following format (where current time is in millisecond using System.currentTimeMillis()): Producer "current time, Placing in the buffer location 0. "current time, Placing 1 in the buffer location 1. "current time, Placing 2 in the buffer location 2. "current time, Placing 9 in the buffer location 9. "current time, Placing 10 in the buffer location 0. "current time, Placing 11 in the buffer location 1. "current time", Placing 14 in the buffer location 4. "current time, Placing 0 in the buffer location 5. "current time, Placing 1 in the buffer location 6. "current time, Placing 2 in the buffer location 7. 3. Consumer Thread Consumer thread consumes integers (messages), 0-14, placed in the buffer by the producer thread. The consumer thread first checks if the buffer is empty or not. At this moment, make sure the consumer thread always waits random period of time (10-100 milliseconds) before checking the buffer. This is to create randomness in the program execution. If the buffer is empty, it waits another random period of time (10100 milliseconds). If the buffer is not empty, then it takes an 3. Consumer Thread Consumer thread consumes integers (messages), 0-14, placed in the buffer by the producer thread. The consumer thread first checks if the buffer is empty or not. At this moment, make sure the consumer thread always waits random period of time (10-100 milliseconds) before checking the buffer. This is to create randomness in the program execution. If the buffer is empty, it waits another random period of time (10-100 milliseconds). If the buffer is not empty, then it takes an integer (message), which is placed in the buffer at the earliest time, from the buffer. (based on the FIFO policy) Every time consumer thread consumes a message and integer) from the buffer, it makes a log in the file (say, consumer.txt) in the following format (where current time is in millisecond): Consumer "current time", Consuming 0 from the buffer location 0. "current time", Consuming 1 from the buffer location 1. "current time", Consuming 2 from the buffer location 2. "current time", Consuming 9 from the buffer location 9. "current time", Consuming 10 from the buffer location 0. "current time", Consuming 11 from the buffer location 1. "current time", Consuming 14 from the buffer location 4. "current time", Consuming 0 from the buffer location 5. "current time", Consuming 1 from the buffer location 6. "current time", Consuming 2 from the buffer location 7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!