Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a Java, program with two processes, a producer and a consumer. The producer process consists of a loop that writes the loop count (a

Make a Java, program with two processes, a producer and a consumer.

The producer process consists of a loop that writes the loop count (a value from 0 to 4) into a variable that it shares with the consumer process (this variable is to be initialized to 100). On each pass through the loop, before the producer writes into the shared variable, it does a random wait of from one to three seconds (compute a new random wait value on each pass through the loop). The loop is to be executed five times.

The consumer process consists of a loop that reads the variable it shares with the producer five times and computes the sum of the values it has read. On each pass through the loop before it reads the shared variable, it does a random wait of from one to three seconds (compute a new random value on each pass through the loop). When the loop finishes, the program is to write the sum into a file.

You must run the program twice. Note that the output from the runs will almost certainly be different if you have written your program correctly. (Mine is only output the same number all time)

This program must output to a data file like "output.txt"

The contents of the output file should look something like this (where ### is your computed sum).

Jack Smith

Assignment X

The sum is ###

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

a. What are S, F, and P? Pg45

Answered: 1 week ago

Question

Ensure continued excellence in people management.

Answered: 1 week ago

Question

Enhance the international team by recruiting the best people.

Answered: 1 week ago