Professional Documents
Culture Documents
Name:Riya Mate
Gr no:1710954
____________________________________________________________________________
Consumer.java:
____________________________________________________________
package psuo_thread;
import java.util.*;
import java.util.concurrent.*;
public class Consumer implements Runnable {
private BlockingQueue<Integer> queue;
private String threadId;
while (true) {
/*the poll method () takes a specified unit of time
as parameter and waits for specified period of time after which the lock is
released*/
Integer number = queue.poll(10, TimeUnit.SECONDS);
consume(number);
Thread.sleep(1000);
}
______________________________________________________________
Producer.java:
package psuo_thread;
import java.util.*;
import java.util.concurrent.*;
public class Producer implements Runnable {
private BlockingQueue<Integer> queue;
Thread.sleep(500);
}
System.out.println("Producer stopped.");
return number;
}
____________________________________________________________________
ProducerConsumerTest.java:
package psuo_thread;
import java.util.*;
import java.util.concurrent.*;
producer.start();
consumer1.start();
consumer2.start();
}
}