Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M9525691

Have any Question?


Related Questions in Java

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As