Program of consumer Producer <p>I need to make a consumer producer problem for homework. I am stuck repeating the the thread. Only 1 object is produced and only 1 object is consumed. If object is present in array then producer does not produce and wait till consumer consumes it. </p> <pre><code>class PC extends Thread{ static int i=1; static int storage[]=new int[1]; String info; PC(String _info) { this.info=_info; } public synchronized void consume() { if(storage[0]==-1) { try { System.out.println("C: 0" ); wait(); } catch(InterruptedException e) { System.out.println("InterruptedException caught"); } } else { System.out.println("C: " + storage[0]); storage[0]=-1; i++; notify(); } } public synchronized void prod() { if(storage[0]!=-1) { try { System.out.println("P: 0" ); wait(); } catch(InterruptedException e) { System.out.println("InterruptedException caught"); } } else { storage[0]=i; System.out.println("P: " + storage[0]); notify(); } } public void run() { if(info=="producer"){ prod(); } else consume(); } public static void main(String args[]) { storage[0]=-1; PC consumer =new PC("consumer"); PC producer =new PC("producer"); consumer.start(); producer.start(); } </code></pre> <p>}</p>