Question: The producer-consumer code for storing in a single integer was explained in class. Now, that code would be extended to be used for an array

The producer-consumer code for storing in a single integer was explained in class. Now, that code would be extended to be used for an array of integers where the producer or consumer will add or consume from one end of the array only; that means items will be added at last of the array and consumed from last of the array as well. The code below shows the extended version of Q and also the get() method has been changed accordingly. Now, you have to write code for the 'put(int n) method only so that it works correctly. ONLY write the 'put' method in answer. public class Q { synchronized int get() { while(isEmpty) int n; try { int size: wait(); int content: catch(InterruptedException e) { System.out.println("InterruptedException caught"); Q(int size): } n=new int[size]; this.size = size; System.out.println("Got("+content+");"-n[content]); content=-1: content- } notifyo; return n content+1]: boolean isFullO // end of get return content=={size-1); } Il you have to write the code for put() method boolean isEmpty return content // end of class Q }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
