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.

Example:
Print out of what the outputs of the executing programs look like
> java ProducerConsumer
Producer: Generated 100,000 items, Cumulative value of generated items=abc.def
Consumer: Consumed 100,000 items, Cumulative value of consumed items=abc.def
Producer: Generated 200,000 items, Cumulative value of generated items=ghi.jkl
Consumer: Consumed 200,000 items, Cumulative value of consumed items=ghi.jkl
Producer: Generated 300,000 items, Cumulative value of generated items=mno.pqr
Consumer: Consumed 300,000 items, Cumulative value of consumed items=mno.pqr
Producer: Generated 400,000 items, Cumulative value of generated items=stu.vwx
Consumer: Consumed 400,000 items, Cumulative value of consumed items=stu.vwx
Producer: Generated 500,000 items, Cumulative value of generated items=yza.bcd
Consumer: Consumed 500,000 items, Cumulative value of consumed items=yza.bcd
Producer: Generated 600,000 items, Cumulative value of generated items=efg.hij
Consumer: Consumed 600,000 items, Cumulative value of consumed items=efg.hij
Producer: Generated 700,000 items, Cumulative value of generated items=klm.nop
Consumer: Consumed 700,000 items, Cumulative value of consumed items=klm.nop
Producer: Generated 800,000 items, Cumulative value of generated items=qrs.tuv
Consumer: Consumed 800,000 items, Cumulative value of consumed items=qrs.tuv
Producer: Generated 900,000 items, Cumulative value of generated items=wxy.zab
Consumer: Consumed 900,000 items, Cumulative value of consumed items=wxy.zab
Producer: Generated 1,000,000 items, Cumulative value of generated items=cde.fgh
Consumer: Consumed 1,000,000 items, Cumulative value of consumed items=cde.fgh
Producer: Finished generating 1,000,000 items
Consumer: Finished consuming 1,000,000 item
Exiting …

Java, Programming

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

Have any Question?


Related Questions in Java

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 ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

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 ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

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 ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

  • 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