Program for solving the producer consumer problem, JAVA Programming

Assignment Help:

For this assignment we will be solving the producer-consumer problem with a bounded buffer. You are required to implement this assignment in Java. There are three components in this assignment.

(1) The Bounded Buffer: This buffer can hold a fixed number of items. The number of elements in this buffer is limited to 1000. This buffer needs to be a first-in first-out (FIFO) buffer. You should implement this as a Circular Buffer that satisfies the FIFO property and is restricted to hold at most 1000 items at a time. 

(2) Producer: The producer is responsible for producing data items to be added to the buffer. If the buffer is full, the producer must wait for the consumer to consume at least one item before it can add a new item to the buffer. The producer is required to produce a total of 1,000,000 items. The item that the producer adds to the buffer is a random Double that is generated using java.util.Random.

    Random random = new Random();

    Double bufferElement = random.nextDouble() * 100.0;

(3) Consumer:

The consumer is responsible for consuming elements from the buffer. If the buffer is empty the consumer must wait for the producer to add an item to the buffer. The consumer is required to consume all elements (1,000,000) generated by the producer.

There should be exactly one instance of the buffer, producer, and consumer. The producer and consumer must reference the same buffer. You can only use wait () and notify()  as the  primitives to synchronize access to the buffer.

 Correctness:

To verify the correctness of your program both the producer and consumer are required to maintain running totals of the values of the items added-to/removed-from the buffer. This would be maintained in a variable bufferValueCounter. 

Since the buffer is a FIFO buffer, the value reported for the two items below should be the same:

(a) The first N elements generated by the producer

(b) The first N elements consumed by the consumer 

Requirements of Task

1) Implement the FIFO Circular Buffer and ensure that the buffer can hold a maximum of 1000 items at a time.

2) Consumer should wait if there are no items in the buffer

3) Producer should wait if the buffer is full

4) Ensure that the producer can produce 1,000,000 items and the consumer can consume 1,000,000, items with a bounder buffer that can hold at most 1000 items at a time.

a. You should not run out of memory. Remember, your producer should not produce if the buffer is full. You should not set the size of the Java VM in your makefile or expect that the JVM will be set to a certain value.

b. Your solution must satisfy the correctness constraint i.e. you consume each item exactly once, in the order that it was produced, and demonstrate this by printing out the value of your counter (at both the producer and consumer) every time you have produced or consumed 100,000 elements. See the example output below; note how the counter values match at the producer and consumer for the same N.

c. There should be no deadlock. Your program will be executed 5 times, and it should run to completion every time without a deadlock.


Related Discussions:- Program for solving the producer consumer problem

Minimal spanning tree decreasing edge algorithm, THE FOLLOWING PROGRAM SHOU...

THE FOLLOWING PROGRAM SHOULD BE JAVA IN ECLIPSE Minimal Spanning Tree Decreasing Edge Dismissal Reverse-delete algorithm. Develop an implementation that computes the MST as fol

Write short notes on (i) rmi and (ii) corba, Question 1 Write a program in...

Question 1 Write a program in Java to find the highest of any five numbers. How do you compile and execute this Java program? Question 2 Write a program to explain the Except

#, Consider the following code? What input is needed for x in order for the...

Consider the following code? What input is needed for x in order for the sum variable that is output at the end of the code to be 12 ? (In other words: what do I need to make X be

Explain about the dynamic java, Dynamic JAVA Class and type informatio...

Dynamic JAVA Class and type information is kept around at runtime. This allows runtime loading and inspection of code in a very flexible way.

Functions in javascript, These are the central working units of JavaScript....

These are the central working units of JavaScript. Almost all the scripting code employs one or more functions to obtain the desired result. If you desire your page to provide cert

Difference b/w software platform and java platform, Java platform is a soft...

Java platform is a software-only platform independent, which runs on top of other hardware-based platforms like WINDOWS, UNIX, NT etc.   The Java platform has 2 main com

What are not allowed within the ejb container? , In  order  to  provide  po...

In  order  to  provide  portable  and  reliable  EJB  elements,  the  following  restrictions  apply  to  EJB  code implementation: 1. Avoid using static non-final fields. Defin

Educational app, CP5307 Assessment Task 3 Coding Project Specification SP22...

CP5307 Assessment Task 3 Coding Project Specification SP22, 2019 Brisbane Description Another type of app found on app stores are “educational games”. There are immersive full-

Define cross-cutting functionality , An aspect is the cross-cutting functio...

An aspect is the cross-cutting functionality that you are executing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is somet

Different messaging paradigms jms supports, What are the different messagin...

What are the different messaging paradigms JMS supports? Ans) Publish and Subscribe i.e. pub/suc and Point to Point i.e. p2p.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd