Question: Enhance the program of Exercise E22.3 by supplying a variable number of producer and consumer threads. Prompt the program user for the numbers. Data
Enhance the program of Exercise ••• E22.3 by supplying a variable number of producer and consumer threads. Prompt the program user for the numbers.
Data from exercise 22.3
Implement a Queue class whose add and remove methods are synchronized. Supply one thread, called the producer, which keeps inserting strings into the queue as long as there are fewer than ten elements in it. When the queue gets too full, the thread waits.
As sample strings, simply use time stamps new Date().toString(). Supply a sec ond thread, called the consumer, that keeps removing and printing strings from the queue as long as the queue is not empty. When the queue is empty, the thread waits. Both the consumer and producer threads should run for 100 iterations.
Step by Step Solution
3.18 Rating (159 Votes )
There are 3 Steps involved in it
To enhance the Exercise E223 we can prompt the users to input the number of producer and consumer threads they want to create Following is a way to do ... View full answer
Get step-by-step solutions from verified subject matter experts
